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

相关推荐
LSL666_17 分钟前
Linux命令
linux·运维·服务器
笨笨饿39 分钟前
32_复变函数在工程中实际应用区别于联系
linux·服务器·c语言·人工智能·单片机·算法·学习方法
Bert.Cai41 分钟前
Linux pwd命令详解
linux·运维
Wasim4041 小时前
【Linux】网络命令
linux·网络安全·linux网络命令·linux网络安全入门
BUG_MeDe1 小时前
从Json对象中提取某个对象的一点注意--libjson-c
linux·json
坚持就完事了1 小时前
Linux的which命令
linux·运维·服务器
skywalk81631 小时前
kitto_plus报错:AttributeError: module ‘kotti_plus‘ has no attribute ‘security‘
linux·开发语言·python
和小潘一起学AI1 小时前
centOS安装neo4j
linux·运维·服务器
HealthScience2 小时前
H20服务器多卡运行有错误gpu_partition ,tmux错误
linux·运维·服务器
_Emma_2 小时前
【Raspberry PI】Raspberry Pi HEVC (H.265) 硬件解码器
linux·驱动开发·视频编解码