需要拦截HID键盘事件(然后阻止它们)

需要拦截HID键盘事件(然后阻止它们),第1张

需要拦截HID键盘事件(然后阻止它们)

因此,根据我在此处找到的帖子,我整理了一个概念验证应用

它确实满足了我的要求-即使我仍然会分享我的解决方案。

#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <errno.h>#include <fcntl.h>#include <dirent.h>#include <linux/input.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/select.h>#include <sys/time.h>#include <termios.h>#include <signal.h>int main(int argc, char* argv[]){    struct input_event ev[64];    int fevdev = -1;    int result = 0;    int size = sizeof(struct input_event);    int rd;    int value;    char name[256] = "Unknown";    char *device = "/dev/input/event3";    fevdev = open(device, O_RDONLY);    if (fevdev == -1) {        printf("Failed to open event device.n");        exit(1);    }    result = ioctl(fevdev, EVIOCGNAME(sizeof(name)), name);    printf ("Reading From : %s (%s)n", device, name);    printf("Getting exclusive access: ");    result = ioctl(fevdev, EVIOCGRAB, 1);    printf("%sn", (result == 0) ? "SUCCESS" : "FAILURE");    while (1)    {        if ((rd = read(fevdev, ev, size * 64)) < size) { break;        }        value = ev[0].value;        if (value != ' ' && ev[1].value == 1 && ev[1].type == 1) { printf ("Code[%d]n", (ev[1].pre));        }    }    printf("Exiting.n");    result = ioctl(fevdev, EVIOCGRAB, 1);    close(fevdev);    return 0;}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5009780.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-14
下一篇 2022-11-14

发表评论

登录后才能评论

评论列表(0条)

保存