linux模拟按键
来源:互联网 发布:centos twisted 安装 编辑:程序博客网 时间:2024/05/16 13:07
#include <stdio.h>#include <stdlib.h>#include <signal.h>#include <sys/fcntl.h>#include <sys/ioctl.h>#include <sys/mman.h>#include <sys/time.h>#include <linux/input.h>int main (){ int keys_fd; char ret[2]; char a; struct input_event t,t0;struct timeval tv; struct timezone tz;int pressed_times;pressed_times = 0; keys_fd = open ("/dev/input/event0", O_RDWR); if (keys_fd <= 0) { printf ("open /dev/input/event0 device error!\n"); return 0; } //if (read (keys_fd, &t, sizeof (t)) == sizeof (t)); while (1) { a = getchar(); printf("Input char: %c",a); switch(a) { case 'p': printf ("Pressed once!\n"); gettimeofday(&t.time, 0); t.type = EV_ABS; t.value = 1; t.code = 57; //x if(write(keys_fd, &t, sizeof (t)) < 0) printf("write event failed!!"); t.type = EV_ABS; t.value = 226; t.code = 53; //x if(write(keys_fd, &t, sizeof (t)) < 0) printf("write event failed!!"); t.type = EV_ABS; t.value = 273; t.code = 54; //y if(write(keys_fd, &t, sizeof (t)) < 0) printf("write event failed!!"); t.type = EV_KEY; // key t.value = 1; t.code = 330; if(write(keys_fd, &t, sizeof (t)) < 0) printf("write event failed!!"); t.type = EV_ABS; t.value = 226; t.code = 0; //x if(write(keys_fd, &t, sizeof (t)) < 0) printf("write event failed!!"); t.type = EV_ABS; t.value = 273; t.code = 1; //y if(write(keys_fd, &t, sizeof (t)) < 0) printf("write event failed!!"); t.type = EV_SYN; t.code = SYN_REPORT; t.value = 0; if(write(keys_fd, &t, sizeof (t)) < 0) printf("write event failed!!"); break; case 'r': printf ("Released once!\n"); gettimeofday(&t.time, 0); t.type = EV_ABS; t.value = -1; t.code = 57; //y if(write(keys_fd, &t, sizeof (t)) < 0) printf("write event failed!!"); t.type = EV_KEY; t.value = 0; t.code = 330; if(write(keys_fd, &t, sizeof (t)) < 0) printf("write event failed!!"); t.type = EV_SYN; t.code = SYN_REPORT; t.value = 0; if(write(keys_fd, &t, sizeof (t)) < 0) printf("write event failed!!"); break; case 't': t.type = EV_ABS; gettimeofday(&t.time, 0); t.type = EV_ABS; t.value = 690; t.code = 53; //x if(write(keys_fd, &t, sizeof (t)) < 0) printf("write event failed!!"); t.type = EV_ABS; t.value = 145; t.code = 54; //y if(write(keys_fd, &t, sizeof (t)) < 0) printf("write event failed!!"); t.value = 690; t.code = 0; //x if(write(keys_fd, &t, sizeof (t)) < 0) printf("write event failed!!"); t.type = EV_ABS; t.value = 145; t.code = 1; //y if(write(keys_fd, &t, sizeof (t)) < 0) printf("write event failed!!"); t.type = EV_SYN; t.code = SYN_REPORT; t.value = 0; if(write(keys_fd, &t, sizeof (t)) < 0) printf("write event failed!!"); break; case 'e': close (keys_fd); exit(1); default: break; } } return 0;}
0 0
- Linux模拟按键输入
- linux模拟按键
- linux 下如何通过软件模拟按键
- linux模拟键盘按键方案(收藏)
- linux下鼠标键盘按键的模拟
- Android(Linux)模拟按键、触摸屏等事件
- linux 应用层模拟按键输入
- 模拟按键发送给linux开发板
- 模拟按键
- 模拟按键
- 按键模拟
- 模拟按键
- 模拟按键
- linux下如何模拟按键输入和模拟鼠标?
- linux下如何模拟按键输入和模拟鼠标?
- [转]linux下如何模拟按键输入和模拟鼠标
- linux下如何模拟按键输入和模拟鼠标
- linux下如何模拟按键输入和模拟鼠标
- 网狐框架分析六--整体框架 20150623
- Linux下Qt Designer 程序设计步骤详解
- 查看网络图片
- 使用testNG进行并发性能测试
- JAVA中重写equals()方法为什么要重写hashcode()方法说明
- linux模拟按键
- 微信APP支付
- 解析Android游戏中获取电话状态进行游戏暂停或继续的解决方法
- Valid Number
- .html .val .text 的区别
- Matlab定义子函数
- Android高效显示图片详解(一)
- ps、grep和kill联合使用杀掉进程
- NodeJs学习笔记一(ubuntu下环境搭建)