grab raw keyboard input from event device node
来源:互联网 发布:pb程序员 编辑:程序博客网 时间:2024/06/08 09:38
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <dirent.h>
#include <linux/input.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/select.h>
#include <sys/time.h>
#include <termios.h>
#include <signal.h>
void handler (int sig)
{
printf ("nexiting...(%d)n", sig);
exit (0);
}
void perror_exit (char *error)
{
perror (error);
handler (9);
}
int main (int argc, char *argv[])
{
struct input_event ev[64];
int fd, rd, value, size = sizeof (struct input_event);
char name[256] = "Unknown";
char *device = NULL;
//Setup check
if (argv[1] == NULL){
printf("Please specify (on the command line) the path to the dev event interface device\n");
exit (0);
}
if ((getuid ()) != 0)
printf ("You are not root! This may not work...\n");
if (argc > 1)
device = argv[1];
//Open Device
if ((fd = open (device, O_RDONLY)) == -1)
printf ("%s is not a vaild device.\n", device);
//Print Device Name
ioctl (fd, EVIOCGNAME (sizeof (name)), name);
printf ("Reading From : %s (%s)\n", device, name);
while (1){
if ((rd = read (fd, ev, size * 64)) < size)
perror_exit ("read()\n");
value = ev[0].value;
if (value != ' ' && ev[1].value == 1 && ev[1].type == 1){ // Only read the key press event
printf ("Code[%d]\n", (ev[1].code));
}
}
return 0;
}
yantai:/home/shell.albert # ./a.out /dev/input/event0
Reading From : /dev/input/event0 (AT Translated Set 2 keyboard)Code[30]
aCode[48]
bCode[46]
cdCode[28]
Code[18]
eCode[33]
fCode[34]
gCode[35]
hCode[23]
iCode[36]
jCode[37]
kCode[38]
lCode[50]
mCode[49]
nCode[24]
oCode[25]
pCode[16]
qCode[19]
rCode[31]
sCode[20]
tCode[22]
uCode[47]
vCode[17]
wCode[44]
zCode[45]
xCode[21]
yCode[44]
zCode[29]
Code[46]
^C
yantai:/home/shell.albert #
by zhangshaoyan at May 20,2015.
We get the codes are same as defined in linux/input.h.
- grab raw keyboard input from event device node
- Getting Input from the Keyboard
- /dev/input/event* linux keyboard mouse event simulation
- Keyboard Input
- how to detemine event file node belongs to which device
- 在tslib移植中,出现tslib: Selected device is not a Linux input event device
- Leap Left Grab和 Event hand Grabbed
- Linux Input 子系统Event Interface详解 <一> 得到Input Device信息
- input device
- input device
- Device Input
- Keyboard Input Overview
- Using Keyboard Input
- VC++ Keyboard Input
- Keymaps and Keyboard Input
- Keymaps and Keyboard Input
- Handling Keyboard Input
- Grab a picture from a FLV file
- 引用多个spring-mVC配置文件
- LeetCode Count and Say Simulation
- 【C语言】实现一个简单的通讯录
- 浅谈ES6的 promise API
- iOS开发block(二)
- grab raw keyboard input from event device node
- cc.pool 缓存池
- x264源代码简单分析:滤波(Filter)部分
- 进程和线程概念介绍
- 透过 Linux 内核看无锁编程
- OC-1-基础语法
- 我的第一篇技术博客
- Solr多字段与或关系查询【需要完善】
- #ifndef 与 #program once 的区别