根据 keycode 获取按键名称

根据 keycode 获取按键名称

我正在编写一个使用 的 shell 脚本xinput,并且我想使用 中的键码获得用户所输入内容的人性化描述xinput

例如,A生成 38.Ctrl是 37。

我如何从代码中获取这些键名?

答案1

如果您在 Xorg 上使用xev:它会打开一个窗口,捕获所有事件(包括击键)并显示结果,例如:

enter code KeyPress event, serial 40, synthetic NO, window 0x5400001,
root 0xc2, subw 0x5400002, time 29136757, (50,54), root:(1311,78),
state 0x1, keycode 38 (keysym 0x41, A), same_screen YES,
XLookupString gives 1 bytes: (41) "A"
XmbLookupString gives 1 bytes: (41) "A"
XFilterEvent returns: False

也许看看https://wiki.archlinux.org/index.php/extra_keyboard_keys更多细节。

相关内容