Check if keyboard key is down
-
wrote on 14 Sept 2011, 21:48 last edited by
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.
-
wrote on 14 Sept 2011, 21:51 last edited by
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. -
wrote on 14 Sept 2011, 21:53 last edited by
... 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. :)
-
wrote on 15 Sept 2011, 07:14 last edited by
[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...
-
wrote on 15 Sept 2011, 15:00 last edited by
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/5