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

相关推荐
鸠摩智首席音效师6 小时前
如何在 Linux 中将文件复制到多个目录 ?
linux·运维·服务器
香蕉你个不拿拿^7 小时前
Linux进程地址空间解析
linux·运维·服务器
人间打气筒(Ada)7 小时前
Linux学习~日志文件参考
linux·运维·服务器·学习·日志·log·问题修复
xuhe28 小时前
Claude Code配合Astro + GitHub Pages:为 sharelatex-ce 打造现代化的开源项目宣传页
linux·git·docker·github·浏览器·overleaf
charlie1145141918 小时前
RK3568跑Arch Linux全路程指南(以正点原子的RK3568开发板为例子)
linux·嵌入式·rootfs·教程·环境配置·嵌入式linux·工程实践
爆米花byh8 小时前
在RockyLinux9环境的Doris单机版安装
linux·数据库·database
筱白爱学习10 小时前
RestHighLevelClient详细使用手册
linux·服务器·php
若谷老师10 小时前
21.WSL中部署gnina分子对接程序ds
linux·人工智能·ubuntu·卷积神经网络·gnina·smina
啊辉的科研13 小时前
植物单细胞RNA-seq分析教程3-2025年版
linux·r语言
Norach13 小时前
ubuntu22.04安装ssh-server与realvnc-server
linux·服务器·经验分享·ubuntu·ssh·vnc