Linux查看键鼠输入

文章目录

本文简单介绍几种在linux下查看键鼠输入的方法

通过打开input设备来读取输入

程序如下,使用时需要看情况修改input设备路径

c 复制代码
#include <fcntl.h>
#include <linux/input.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#define DEV_PATH "/dev/input/event1" // difference is possible
int main()
{
    int keys_fd;
    char ret[2];
    struct input_event t;
    keys_fd = open(DEV_PATH, O_RDONLY);
    if (keys_fd <= 0) {
        printf("open /dev/input/event1 device error!\n");
        return -1;
    }
    while (1) {
        if (read(keys_fd, &t, sizeof(t)) == sizeof(t)) {
            if (t.type == EV_KEY)
                if (t.value == 0 || t.value == 1) {
                    printf("key %d %s\n", t.code, (t.value) ? "Pressed" : "Released");
                    if (t.code == KEY_ESC)
                        break;
                }
        }
    }
    close(keys_fd);
 
    return 0;
}

通过第三方程序获取

xev

xinput

evtest

参考

Linux捕捉鼠标事件和键盘事件的方法

相关推荐
papaofdoudou14 分钟前
QEMU和KVMTOOL在GPA(IOVA)和HVA映射方面的异同
linux·运维·服务器
艾莉丝努力练剑1 小时前
文件描述符fd:跨进程共享机制
java·linux·运维·服务器·开发语言·c++
原来是猿1 小时前
Linux-【文件系统下】
linux·运维·数据库
勇闯逆流河1 小时前
【Linux】linux进程概念(冯洛伊曼体系、操作系统、进程详解)
linux·运维·服务器
姓刘的哦1 小时前
RK3568之热插拔
linux
Penguido1 小时前
解决 VS Code 中 Git 推送报错:ECONNREFUSED vscode-git.sock 与鉴权失败
linux·git·vscode
Han.miracle1 小时前
Lombok 构造相关核心注解全解析
java·linux·算法
爱丽_1 小时前
Linux 安装 MySQL 与远程连接排障(yum 方案)
linux·运维·mysql
Felven2 小时前
麒麟信安系统忘记root密码解决说明
linux·运维·服务器
IMPYLH2 小时前
Linux 的 base64 命令
linux·运维·服务器·bash·shell