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

相关推荐
豐儀麟阁贵2 小时前
9.4字符串操作
java·linux·服务器·开发语言
minji...2 小时前
Linux 进程控制(二) (进程等待wait/waitpid)
linux·运维·服务器·数据结构
知南x2 小时前
【正点原子STM32MP157 启动篇】(3) STM32MP1 二进制头部信息+Linux 系统启动过程
linux·stm32·嵌入式硬件·stm32mp157
IT 乔峰2 小时前
Apache工作原理详细说明
linux·apache
fufu03112 小时前
Linux环境下的C语言编程(三十六)
linux·c语言·开发语言·数据结构·算法
小嘟嘟132 小时前
第2章 Shell 变量与参数传递:3 种定义方式 + 避坑指南
linux·运维·shell
looking_for__2 小时前
【Linux】进程概念
linux
Eric.Lee20212 小时前
ubuntu系统在bashrc文件中对conda进行启用设置
linux·运维·python·ubuntu·conda
mooyuan天天2 小时前
CobaltStrike横向渗透之Https Beacon实战2(跳板机Linux)
linux·内网渗透·横向移动·cobalt strike
model20052 小时前
Alibaba linux 3安装mapserver
linux·运维·服务器