gpt4 book ai didi

Linux - 在没有 xlib 的 RECORD 的情况下有什么方法可以获得全局按键? (DBus/HAL/等等?)

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:30:47 25 4
gpt4 key购买 nike

I was looking at how to capture global kepresses on Ubuntu Linux 不管哪个窗口有焦点。人们建议看一些节目。但他们都使用 XLib 中的 RECORD 东西,即 is broken in Ubuntu 。还有其他方法可以捕获 Ubuntu 上的所有按键吗?使用 HAL 怎么样?总线?

最佳答案

您可以打开与键盘对应的/dev/input/eventN 设备并从那里读取键盘事件。您甚至可以从非 X 控制台获得键盘事件。这是“evdev”界面。

来自内核源代码中的Documentation/input/input.txt:

You can use blocking and nonblocking reads, also select() on the /dev/input/eventX devices, and you'll always get a whole number of input events on a read. Their layout is:

struct input_event {
struct timeval time;
unsigned short type;
unsigned short code;
unsigned int value;
};

time is the timestamp, it returns the time at which the event happened. Type is for example EV_REL for relative moment, REL_KEY for a keypress or release. More types are defined in include/linux/input.h.

code is event code, for example REL_X or KEY_BACKSPACE, again a complete list is in include/linux/input.h.

value is the value the event carries. Either a relative change for EV_REL, absolute new value for EV_ABS (joysticks ...), or 0 for EV_KEY for release, 1 for keypress and 2 for autorepeat.

关于Linux - 在没有 xlib 的 RECORD 的情况下有什么方法可以获得全局按键? (DBus/HAL/等等?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1906493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com