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

相关推荐
学嵌入式的小杨同学5 小时前
从零打造 Linux 终端 MP3 播放器!用 C 语言实现音乐自由
linux·c语言·开发语言·前端·vscode·ci/cd·vim
EverydayJoy^v^5 小时前
RH134学习进程——十二.运行容器(1)
linux·运维·容器
syseptember5 小时前
Linux网络基础
linux·网络·arm开发
zl_dfq6 小时前
Linux 之 【多线程】(线程的概念、Linux中的线程、页表)
linux
郝亚军7 小时前
如何在Ubuntu和win10/11之间通过samba访问对方的文件
linux·服务器·ubuntu
曦云沐7 小时前
【避坑指南】Ubuntu更新报错“Repository is not signed”的快速修复
linux·ubuntu·docker
带土18 小时前
10. .out文件
linux
STCNXPARM8 小时前
Linux camera之V4L2子系统详解
android·linux·camera·v4l2架构
yueyuexiaokeai19 小时前
linux kernel常用函数整理
linux·c语言
郝亚军10 小时前
ubuntu-18.04.6-desktop-amd64安装步骤
linux·运维·ubuntu