Linux在Windows中等同于Window的GetAsyncKeyState? [英] What's the Linux equivalent of Window's GetAsyncKeyState?
问题描述
我正在使用c ++,我需要确定是否按下了Shift键.在Windows中,我只能使用GetAsyncKeyState.如何在Linux中执行此操作? 我无法以root用户身份运行.
I'm using c++, and I need to determine if a shift key is pressed. In windows, I can just use GetAsyncKeyState. How can I do this in Linux? I cannot run as root.
推荐答案
在X Windows下,您可以加载X Keyboard扩展名并调用XkbGetState()
以获取当前的键盘状态.如果按下Shift键,则由XkbGetState()
设置的XkbStateRec
结构的base_mods
字段将设置ShiftMask
位.此处的完整文档: https://www. x.org/releases/X11R7.7/doc/libX11/XKB/xkblib.html#Determining_Keyboard_State
Under X Windows, you can load the X Keyboard extension and call XkbGetState()
to get the current keyboard state. If the shift key is being pressed, the base_mods
field of the XkbStateRec
structure set by XkbGetState()
will have the ShiftMask
bit set. Full documentation here: https://www.x.org/releases/X11R7.7/doc/libX11/XKB/xkblib.html#Determining_Keyboard_State
或者: https://stackoverflow.com/a/4225290/4474419
这篇关于Linux在Windows中等同于Window的GetAsyncKeyState?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!