Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to add keys to QT which doesn't support



  • Hello,

    I'm curious about keys which didn't define in qt event keys, some keys defined like Key_VolumeUp/Down and a lot more but some keys like brightness up/down didn't define in Qt in this case for example linux sends key event of that key which didn't define in qt so I can't get the key.

    Is it possible to add some keys into qt without modifing and compiling QT source?
    Please let me know if you have any other solutions about this issue.

    I appreciate any idea

    Yours,
    Alien



  • Hi @Alien,
    The QKeyEvent class has a method for you: nativeVirtualKey, that returns the native virtual key (the one sent by linux).

    So if you want to get those brightness keys, you must search for their natives codes. I'm not using linux, but it seems to be these ones :

    #define KEY_BRIGHTNESSDOWN	224
    #define KEY_BRIGHTNESSUP	225
    

    So now, in your key press event handler, it could be something like :

    void YourWidget::keyPressEvent(QKeyEvent *event){
        if(event->nativeVirtualKey() == KEY_BRIGHTNESSDOWN)
            // brightness down
        else if(event->nativeVirtualKey() == KEY_BRIGHTNESSUP)
            // brightness up
    //...
    }
    

    Hope it helps.



  • Dear @SamurayH ,

    When there is no key defined in qt therefore there is no event for that!
    I implement an application and put your suggested code inside it when my keyboard driver send undefined key to application it can't get related event in qt so I'm not able to handle it.

    Thanks for your reply but it doesn't work!


  • Lifetime Qt Champion

    Hi,

    I would go with a QAbstractNativeEventFilter.

    That should give you access to the events you are looking for.


Log in to reply