I need get the state of the CAPS LOCK using C++. I tried to get the state using XkbGetIndicatorState
, but it doesn't work.
Can someone help me?
I need get the state of the CAPS LOCK using C++. I tried to get the state using XkbGetIndicatorState
, but it doesn't work.
Can someone help me?
I was struggling with the same question but for the NUM_LOCK Key state. I Modified the code found, to find the CAPS_LOCK state:
Here is the code, I hope this helps:
#include <X11/Xlib.h>
Display *dpy = XOpenDisplay(":0");
XKeyboardState x;
printf("led_mask=%lx\n", x.led_mask);
printf("NumLock is %s\n", (x.led_mask & 2) ? "On" : "Off");
printf("CapsLock is %s\n", (x.led_mask & 1) ? "On" : "Off");
Try something like below:
if ((GetKeyState(VK_CAPITAL) & 0x0001)!=0)
cout<<"Caps Lock ON!";
else
cout<<"Caps Lock OFF!";
Or (reference)
Use GetAsyncKeyState with VK_CAPITAL (0x14)