How to get Num Lock and Scroll Lock status

93 Views Asked by At

In my X11 C++ application I need to check modifier keys status. Caps Lock status can be get using XkbGetIndicatorState, here is an example. How to get Num Lock and Scroll Lock status ?

1

There are 1 best solutions below

2
n. m. could be an AI On BEST ANSWER

You want to use XkbGetState. It returns a pointer to XkbStateRec which contains these fields.

  unsigned char            mods;                 /* effective modifiers */
  unsigned char            base_mods;            /* base modifiers */
  unsigned char            latched_mods;         /* latched modifiers */
  unsigned char            locked_mods;          /* locked modifiers */

You want to check the effective modifiers mask. Usually Caps Lock is LockMask, Num Lock is Mod2Mask and Scroll Lock is Mod5Mask (from X11/X.h).