4

I know there were earlier problems with this in < 4.7.4 Qt versions. has this been resolved?

JasonGenX
  • 4,952
  • 27
  • 106
  • 198
  • Some keyboards don't even report the status of the caps lock key; Qt might not be the only problem. – Carl Norum Mar 22 '12 at 21:37
  • See this. [Qt - Password field][1]. This problem was already discussed there. [1]: http://stackoverflow.com/questions/2968336/qt-password-field – shan Mar 23 '12 at 04:48

1 Answers1

3

I don't know any Qt solution.

However this code should work on both windows (not tested) and x11-based 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
}

On X11 don't forget to add -lX11 to LIBS in your qmake project file.

I don't exactly know how to do this on OS X. If you need it, take a look at IOHIKeyboard and its's alphaLock() function. Also check this, especially the function darwinQueryHIDModifiers.

paul
  • 1,212
  • 11
  • 15