-1

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?

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • 4
    What did you try, and in what way didn't it work? Did you try something like this: http://stackoverflow.com/a/9010026/204847 – Mike Seymour Apr 20 '15 at 15:15

2 Answers2

0

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");
boony
  • 1
-6

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)