簡體   English   中英

無法在 C [Ubuntu 16.04LTS] 中捕獲擊鍵

[英]Cannot capture keystrokes in C [Ubuntu 16.04LTS]

一段時間以來,我一直在嘗試在 Ubuntu 16.04LTS 上制作鍵盤記錄器,這就是我目前所擁有的:

#include <stdio.h>
#include <fcntl.h>
#include <linux/input.h>
#include <stdbool.h>

int main()
{
        char devname[] = "/dev/input/event0";
        int device = open(devname, O_RDONLY);
        struct input_event ev; 
        bool logging = true;

        while(logging)
        {
                if (read(device,&ev, sizeof(ev)) >= 0){ 
                        printf("Key: %i State: %i Type: %i\n",ev.code,ev.value,ev.type);
                }
        }

}

但是,當我編譯並運行它(gcc)時,它不輸出任何內容! 我已經嘗試了 /dev/input/by-id 和thensome 中列出的所有設備,但似乎沒有任何效果。

當我使用 GCC 編譯代碼時,我收到警告:

keylogger.c: In function ‘main’:
keylogger.c:15:7: warning: implicit declaration of function ‘read’ [-Wimplicit-function-declaration]
   if (read(device,&ev, sizeof(ev)) >= 0){       
       ^

我不知道這是否與程序的功能有關。

任何幫助表示贊賞! 謝謝!

我想通了,這是一個沒有超級用戶權限的簡單問題。 我使用sudo執行文件,現在一切正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM