[問題] 請問gcc如何模擬鍵盤按鍵?

看板LinuxDev作者 (oeoe)時間16年前 (2009/05/25 10:22), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
Dear all, 請問在linux下用c的話 要怎樣可以模擬鍵盤按鍵? (像MFC有keybd_event) 我有在網路上看到一個範例但無法使用 是有地方寫錯嗎?感謝~ void simulate_key(int fd,int value) { struct input_event event; event.type = EV_KEY; event.code = KEY_0; event.value = value; gettimeofday(&event.time,0); if(write(fd,&event,sizeof(event)) < 0){ printf("simulate key error~~~\n"); return ; } } int main(void) { int fd_kbd = open("/dev/input/event1",O_RDWR); if(fd_kbd<=0){ return -1; } simulate_key(fd_kbd, 1); sleep(1); simulate_key(fd_kbd, 0); return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.133.37.155
文章代碼(AID): #1A6d5l9O (LinuxDev)
討論串 (同標題文章)
文章代碼(AID): #1A6d5l9O (LinuxDev)