Important: Please read the Qt Code of Conduct -

Detect "KeyDown" event in qml

  • Hi
    How can I detect whether a key (e.g. Qt.Key_Space) is down or not? (inside a FocusScope)
    I want to get a single event for start of press only.
    Keys.onPressed is not useful because it is triggered contiguously when I press and hold down space key, the same is true for Key.onReleased
    Very strange behavior, because these handlers are for this purpose, I think :|
    Qt 5.12.4


  • Qt Champions 2017

    You need to use the Keys.onRelease only. Since it is repeate key try to use isAutoRepeat set to true to detect that key is pressed continously.

  • Thanks
    using below code works

    Keys.onReleased: {
        if(event.key === Qt.Key_Space && !event.isAutoRepeat) {
            // code here

Log in to reply