Android原生(Native)C开发之三:鼠标事件篇(捕鼠记)
在做SDL至Android的移植时,键盘事件是能正常捕获到,看了SLD的源码,发现用的device是 /dev/tty0,但是鼠标叫是不能成功捕获,总是得到 0,运行命令查看devices时,显示如下:
# cat /proc/bus/input/devices
cat /proc/bus/input/devices
I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="qwerty"
P: Phys=
S: Sysfs=/class/input/input0
U: Uniq=
H: Handlers=kbd mouse0 event0
B: EV=2f
B: KEY=ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff f
fffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe
B: REL=3
B: ABS=7
B: SW=1
进入 /dev/input 目录,发现在3个device文件:mice,mouse0,event0,分别 cat这3个文件,发现只有 event0 有反应,如下图:
而且不管是点击鼠标还是按键,都有反应,但显示的是一堆乱码,而且点击鼠标出来的东西要多一点,难道这就是传说是的 touchscreen ?!
为了分析 event0 的返回值,写了一段代码 testmice.c,如下:
#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) {
相关文档:
最近做的一些工作需要用到线程池技术,因此参考了一些资料和书籍,如《0bug c/c++商用工程之道》。
为此在linux平台上用纯c写了一个线程池的实现。
在此列出了原代码。
主要用到的数据结构有
1.struct thread_pool_t // thread pool 的实现代码
2.struct thread_pool_token_t &nb ......
来自bccn C语言论坛
首先声明一点,本文为转贴。
浅谈C中的malloc和free
作者:lj_860603 阅读人次:43013 文章来源:本站原创 发布时间:2006-8-5 网友评论(32)条
原帖及讨论:http://bbs.bccn.net/thread-82212-1-1.html
在C语言的学习中,对内 ......
实在无聊中就将原来的一些东西整理了一下,自己是个记性不好的人,隔断时间整理自己,同时也希望可以方便他人。
----------------------------------------------------------------------------------------------------------------------------------------
/**//*************************************************** ......
在 C API 中可用的函数列在下面,并且在下一节更详细地描述。见20.4 C API函数描述。
mysql_affected_rows()
返回被最新的UPDATE, DELETE或INSERT查询影响的行数。
mysql_close()
关闭一个服务器连接。
mysql_connect()
连接一个MySQL服务器。该函数不推荐;使用mysql_real_connect()代替。
mysql_change_user( ......
#i nclude <stdio.h>
#i nclude <dos.h>
#i nclude <conio.h>
#i nclude <graphics.h>
#i nclude <stdlib.h>
#ifdef __cplusplus
#define __CPPARGS ...
#else
#define __CPPARGS
#endif
#define MINBOXSIZE ......