亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: 在偽終端下面怎么捕獲鍵盤? [打印本頁]

作者: wyyzxml    時間: 2014-07-23 09:25
標(biāo)題: 在偽終端下面怎么捕獲鍵盤?
  1. int main(void)
  2. {
  3.         int buttons_fd;
  4.         int key_value,i=0,count;
  5.         struct input_event ev_key;
  6.        
  7.         buttons_fd = open("/dev/input/event2", O_RDWR);
  8.        
  9.         if (buttons_fd < 0)
  10.         {
  11.                 perror("open device buttons");exit(1);
  12.         }
  13.        
  14.         for (;;)
  15.         {
  16.                 count = read(buttons_fd,&ev_key,sizeof(struct input_event));
  17.                
  18.                 for(i=0; i<(int)count/sizeof(struct input_event); i++)
  19.                         if(EV_KEY == ev_key.type)
  20.                                 printf("type:%d,code:%d,value:%d\n",
  21.                                                 ev_key.type,ev_key.code-1,ev_key.value);
  22.                
  23.                 if(EV_SYN==ev_key.type)
  24.                         printf("syn event\n\n");
  25.         }
  26.        
  27.         close(buttons_fd);

  28.         return 0;
  29. }
復(fù)制代碼
這段代碼,在ubuntu本地是OK的,但是如果是ssh到這臺linux上后,就不能捕獲鍵盤輸入了。
請問如何在ssh/telnet后,捕獲鍵盤輸入?

作者: zyr-linux    時間: 2014-07-23 09:55
ssh/telnet后,試試是走tty或者控制臺呢?
作者: guocslock    時間: 2014-07-23 13:58
你說的“不能捕獲”是什么意思?
是read系統(tǒng)調(diào)用沒有讀到結(jié)果還是僅僅沒有看到printf的打。
如果是后者,你通過ssh/telnet上去當(dāng)然無法看到printf的輸出,因為printf是打印到標(biāo)準輸出的。試試把要打印的信息寫到/dev/pts目錄下面的設(shè)備文件去。
作者: guocslock    時間: 2014-07-23 14:00
你說的“不能捕獲”是什么意思?
是read系統(tǒng)調(diào)用沒有讀到結(jié)果還是僅僅沒有看到printf的打?
如果是后者,你通過ssh/telnet上去當(dāng)然無法看到printf的輸出,因為printf是打印到標(biāo)準輸出的。試試把要打印的信息寫到/dev/pts目錄下面的設(shè)備文件去。
作者: wyyzxml    時間: 2014-07-23 14:43
回復(fù) 3# guocslock

ssh上去,看不到/dev/input/eventX文件,所有沒有地方讀這個事件。

   




歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2