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

后端 未结 1 1783
粉色の甜心
粉色の甜心 2020-12-21 01:36

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

相关标签:
1条回答
  • 2020-12-21 01:55

    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.

    0 讨论(0)
提交回复
热议问题