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

相关推荐
Ancelin安心7 分钟前
kali-dirsearch的使用
linux·运维·服务器·python·计算机网络·web安全·网络安全
IT利刃出鞘1 小时前
VMware--解决vmdk越来越大的问题(vmdk瘦身)
linux·ubuntu·vmware
wdfk_prog1 小时前
[Linux]学习笔记系列 -- [driver]base
linux·笔记·学习
月光下的麦克2 小时前
如何查案动态库版本
linux·运维·c++
Vallelonga2 小时前
使用 busybox 制作磁盘镜像文件
linux·经验分享
EndingCoder2 小时前
索引类型和 keyof 操作符
linux·运维·前端·javascript·ubuntu·typescript
石小千2 小时前
Linux清除缓存
linux·运维
weixin_516023072 小时前
VESTA在Linux下的安装
linux·运维·服务器
Nautiluss2 小时前
一起调试XVF3800麦克风阵列(十四)
linux·人工智能·音频·语音识别·dsp开发
耶耶耶耶耶~3 小时前
arch linux 安装
linux·运维·服务器