6

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.

ajfbiw.s
  • 371
  • 1
  • 7
  • 21

1 Answers1

1

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

Alternatively: https://stackoverflow.com/a/4225290/4474419

Community
  • 1
  • 1
Davislor
  • 13,447
  • 2
  • 30
  • 40