1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | #include #include #include #include #include #include void simulate_key(int fd,int kval) //按下kval键 event.value = 1; write(fd,&event,sizeof(event)) ; //同步,也就是把它报告给系统 event.code = SYN_REPORT; write(fd, &event, sizeof(event)); memset(&event, 0, sizeof(event)); event.type = EV_KEY; event.value = 0; event.type = EV_SYN; event.value = 0; /*char cval[3] = "我"; size_t len = strlen(cval); write(2, "我", 6);*/ } void simulate_mouse(int fd) struct input_event event; gettimeofday(&event.time, NULL); event.type = EV_REL; event.value = 10; event.type = EV_REL; event.value = 10; //同步 event.code = SYN_REPORT; { int fd_mouse; if(fd_kbd<=0){ return -1; } fd_mouse = open("/dev/input/event2",O_RDWR); printf("error open mousen"); } int i = 0; // printf("%s",cval);SDFGHJKL; for(i=0; i< 10; i++) simulate_key(fd_kbd, val+i); simulate_mouse(fd_mouse); } close(fd_kbd); |
更多回帖