Linux C監聽鼠標鍵盤操作


代碼:

//monitor.c
#include <stdio.h> #include <linux/input.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int main(int argc, char** argv) { int keys_fd; char ret[2]; struct input_event t; keys_fd = open(argv[1], O_RDONLY); if(keys_fd<=0) { printf("error\n"); return -1; } while(1) { read(keys_fd, &t, sizeof(struct input_event)); printf("key %i state %i type %i\n", t.code, t.value, t.type); } close(keys_fd); return 0; }

編譯:gcc -o monitor monitor.c

查看外設:ls -l /dev/input/    # 外設有多個event0到event5,不確定哪個是鼠標哪個是鍵盤,可以都試試

執行:monitor /dev/input/event2

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM