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

相关推荐
Auv开心14 分钟前
Ubuntu 20.04 默认视频播放器(Totem)无法播放 MP4 文件,通常是因为缺少多媒体编解码器。以下是几种解决方法:
linux·ubuntu·音视频
天空'之城32 分钟前
Linux 系统编程 15:UDP 编程
linux·系统编程·udp协议
utf8mb4安全女神34 分钟前
如果复制windows 内容到 Linux,带入不可见特殊符,怎么解决
linux·运维·服务器
fei_sun1 小时前
网卡、网关、网桥、交换机、路由器
linux·服务器·网络
2601_961593421 小时前
Mac 虚拟机跑 Linux 选哪个?CentOS 8 稳定版适配方案
linux·macos·centos
ljs6482739511 小时前
智慧商城(Smart Mall):基于 Spring Boot + Vue 3 的现代化电商平台实战
linux·vue.js·spring boot·后端
run21professional2 小时前
系统包管理器和语言级包管理器的区别,及其源配置
linux
阿成学长_Cain2 小时前
Linux grpck命令超全详解|校验组文件完整性、修复/etc/group错误实战
linux·运维·服务器·网络
learndiary2 小时前
Linux 维修视频讲解12则
linux·运维·淘宝
Yana.nice3 小时前
Weblogic日志体系
linux