Monday, August 23, 2010

Retrieving CAPS LOCK info using Xlib

#include
#include

int main() {
Display * d = XOpenDisplay((char*)0);
bool caps_state = false;
if (d) {
unsigned n;
XkbGetIndicatorState(d, XkbUseCoreKbd, &n);
caps_state = (n & 0x01) == 1;
}
std::cout << "caps_state = " << std::endl;
return 0;
}

Compile above code using

g++ main.cpp -L/usr/X11R6/lib -lX11


1 comment:

  1. Hi, u can replace this line

    caps_state = (n & 0x01) == 1;

    with this

    _capslock_state = (n & XInternAtom(QX11Info::display(), "Caps Lock", False)) == 1;

    thx you

    ReplyDelete