繁体   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