Qt 4.7.4: Is there a way to find out the status of CAPS LOCK?

I know there used to be problems with this in the <4.7.4 version of Qt. is it allowed?

+4
source share
1 answer

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.

+2
source

Source: https://habr.com/ru/post/1402984/


All Articles