上一篇说过/dev/input/下的设备是各种输入设备
怎么用自己的设备/程序模拟这些输入设备呢?------直接写
比如下面这段代码就可以模拟压下,放开事件
怎么扩展,留备后用
static char TOUCH_DEVICE[256] = "/dev/input/event3";
int touchfd = -1;
static void init_touch()
{
if((touchfd = open(TOUCH_DEVICE, O_RDWR)) == -1)
{
printf("cannot open touch device %s\n", TOUCH_DEVICE);
}
}
static void cleanup_touch()
{
if(touchfd != -1)
{
close(touchfd);
}
}
void TouchEvent(int down, int x, int y)
{
struct input_event ev;
memset(&ev, 0, sizeof(ev));
gettimeofday(&ev.time,0);
ev.type = EV_KEY;
ev.code = BTN_TOUCH;
ev.value = down;
if(write(touchfd, &ev, sizeof(ev)) < 0)
{
printf("write event failed, %s\n", strerror(errno));
}
gettimeofday(&ev.time,0);
ev.type = EV_ABS;
ev.code = ABS_X;
ev.value = x;
if(write(touchfd, &ev, sizeof(ev)