I do not know any Qt solution.
However, this code should work both on both windows (not tested) and on x11-os (works on linux)
#include <X11/XKBlib.h> #include <QX11Info> bool capsOn() { #ifdef Q_WS_WIN // MS Windows version return GetKeyState(VK_CAPITAL) == 1; #elif Q_WS_X11 // X11 version unsigned int n = 0; Display *d = QX11Info::display(); XkbGetIndicatorState(d, XkbUseCoreKbd, &n); return (n & 0x01) == 1; #else # error Platform not supported #endif }
In X11, remember to add -lX11 to LIBS in the qmake project file.
I do not know how to do this on OS X. If you need it, look at IOHIKeyboard and its alphaLock (). Also check this one , especially the darwinQueryHIDModifiers function.
source share