keyboardx11xlib

How to get Num Lock and Scroll Lock status


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 ?


Solution

  • 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).