linux模拟按键
2015-06-30 11:17
357 查看
#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< 4000 /span>(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; }
相关文章推荐
- Linux下Qt Designer 程序设计步骤详解
- Linux 初始化 init 系统3---Systemd
- Linux 初始化 init 系统2---UpStart
- Xen虚拟机磁盘镜像模板制作(四)—CentOS 7
- Linux下的文本编辑器
- linux umask 设置
- Linux进程间通信-共享内存
- 02 Linux操作系统及常用命令
- 在CentOS上安装Mysql
- 01 Linux操作系统基础
- Linux之scp远程拷贝指令
- Linux kernel map
- Linux 初始化 init 系统1---sysvinit
- centos 及windows ntp 时间同步实践
- SELinux学习笔记
- centos同步时间
- linux命令行下的ftp 多文件下载和目录下载
- centos6.5安装vmware-tools
- linux下常用FTP命令 上传下载文件
- Linux中断(interrupt)子系统之五:软件中断(softIRQ)