Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Detect "KeyDown" event in qml

Detect "KeyDown" event in qml

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 686 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MajidKamali
    wrote on last edited by
    #1

    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

    Thanks

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      1
      • M Offline
        M Offline
        MajidKamali
        wrote on last edited by
        #3

        Thanks
        using below code works

        Keys.onReleased: {
            if(event.key === Qt.Key_Space && !event.isAutoRepeat) {
                // code here
            }
        }
        
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved