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

相关推荐
独行soc8 分钟前
2025年渗透测试面试题总结-2025年HW(护网面试) 33(题目+回答)
linux·科技·安全·网络安全·面试·职场和发展·护网
java龙王*26 分钟前
开放端口,开通数据库连接权限,无法连接远程数据库 解决方案
linux
bcbobo21cn1 小时前
Linux命令的命令历史
linux·histsize·histfile
jingyu飞鸟2 小时前
linux系统源代码安装apache、编译隐藏版本号
linux·运维·apache
世事如云有卷舒2 小时前
Ubunt20.04搭建GitLab服务器,并借助cpolar实现公网访问
linux·服务器·gitlab
2401_858286113 小时前
OS15.【Linux】gdb调试器的简单使用
linux·运维·服务器·开发语言·gdb
zjw_rp5 小时前
centos停止维护后更换yum源
linux·运维·centos
行止66 小时前
OpenStack云平台管理
linux·openstack
岁岁岁平安6 小时前
CentOS-7-x86_64解决:使用NAT模式无法ping通www.baidu.com或无法ping 8.8.8.8问题。
linux·运维·centos·centos-7
运维小贺6 小时前
各服务器厂商调整BIOS睿频教程
linux·运维·服务器·性能优化