Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Check if keyboard key is down
QtWS25 Last Chance

Check if keyboard key is down

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 9.1k Views
  • 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
    mirswith
    wrote on last edited by
    #1

    Is there an easy way to simply test if a keyboard key is down? I am in a mouse event and want to know if the ctrl key is down for example.

    Thanks.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Those are two different things.
      The mouse event delivers "modifiers":http://doc.qt.nokia.com/latest/qinputevent.html#modifiers , which are "Ctrl, shift etc.":http://doc.qt.nokia.com/latest/qt.html#KeyboardModifier-enum
      For other keys, you have to use OS specific things.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

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

        ... or listen for key events and store them someplace. I did not realize the mouse event had modifiers, in this case it looks like I am covered.

        Thanks again. :)

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          [quote author="mirswith" date="1316037198"]... or listen for key events and store them someplace.[/quote]

          This will not work 100%. Think of someone put's the focus out of your app, presses shift and then click into your app. You would not get the shift press as key event...

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mirswith
            wrote on last edited by
            #5

            Makes sense. Sounds like we need a new class with the static call, QKeyboard::isKeyDown(int key); I noticed there is a gaming forum here, what is being recommended for games since they will need something along these lines?

            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