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捕捉鼠标事件和键盘事件的方法

相关推荐
new_daimond10 小时前
Linux 服务器内存监控与优化指南
linux·服务器·chrome
一介草民丶10 小时前
Linux | Mongodb 6 离线安装
linux·运维·mongodb
赖small强11 小时前
Linux 线程相关结构对照表与关系图
linux·thread_info·task_struct·thread_struct
Justin_1911 小时前
部署zabbix
linux·centos·zabbix
STUPID MAN11 小时前
Linux使用tomcat发布vue打包的dist或html
linux·vue.js·tomcat·html
mc235611 小时前
Linux实用操作
linux·运维·服务器
半梦半醒*12 小时前
k8s——pod详解2
linux·运维·docker·容器·kubernetes·负载均衡
vvw&12 小时前
如何使用 Nodemon 自动重启 Node.js 应用
linux·运维·服务器·node.js
Bdygsl13 小时前
Linux(3)—— 权限操作
linux
奔跑吧邓邓子13 小时前
【C语言实战(75)】C语言内存探秘:泄漏检测与分析实战
linux·c语言·windows·内存·开发实战·泄露检测