#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <linux/input.h>


static int event0_fd = -1;
struct input_event ev0[64];

//for handling event0, mouse/key/ts
static int handle_event0() {
int button = 0, realx = 0, realy = 0, i, rd;

rd = read(event0_fd, ev0, sizeof(struct input_event) * 64);
if ( rd < sizeof(struct input_event)) return 0;

for (i = 0; i < rd / sizeof(struct input_event); i++) {
printf("", ev0[i].type, ev0[i].code, ev0[i].value);
if (ev0[i].type == 3 && ev0[i].code == 0)
realx = ev0[i].value;
else if (ev0[i].type == 3 && ev0[i].code == 1)
realy = ev0[i].value;
else if (ev0[i].type == 1) {
if (ev0[i].code == 158) {
//if key esc then exit
return 0;
}
} else if (ev0[i].type == 0 && ev0[i].code == 0 && ev0[i].value == 0) {
realx = 0, realy = 0;
}
printf("event(%d): type: %d; code: %3d; value: %3d;\n", i,ev0[i].type, ev0[i].code, ev0[i].value);
}

return 1;
}

int main(void) {
int done = 1;
printf("sizeof(struct input_event) = %d\n", sizeof(struct input_event));

event0_fd = open("/dev/input/event1", O_RDWR);

if ( event0_fd < 0 )
return -1;

while ( done ) {
printf("begin handel_event0…\n");
done = handle_event0();
printf("end handel_event0…\n");
}

if ( event0_fd > 0 ) {
close(event0_fd);
event0_fd = -1;
}

return 0;

}

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. 对RecycleView的多种item布局的封装
  2. Android应用程序窗口(Activity,Window,View
  3. Android dumpsys 使用之分析网络使用情况
  4. [Android]Http通信,HttpService服务端通过
  5. Android高手应该精通哪些内容
  6. Android——使用AIDL实现进程间通讯简单
  7. Android SDK的安装和Android命令行工具
  8. Ubuntu共享WiFi(AP)给Android方法【修正
  9. android根据uri或文件绝对路径获取文件基
  10. ReactNative ART绘制