Home:ALL Converter>How to avoid delayed notice of Modifier key presses, Qt for Linux and Windows?

How to avoid delayed notice of Modifier key presses, Qt for Linux and Windows?

Ask Time:2013-11-13T04:50:52         Author:user405

Json Formatter

Using PyQt4 (4.10.3) and Qt4 (4.8.5) I have an app that should change its appearance when the Shift key is down. The code works perfectly in Mac OSX: as soon as I press a Shift key, my keyPressEvent() method is called with an event showing a keyPress for Shift. Same for Ctl (Cmd on mac) and Alt (opt).

The identical code fails on Linux and Windows because on these platforms, it seems that the press event of a modifier key is not delivered right away. I can press Shift and nothing happens, but when I release the Shift key, then my keyPressEvent() and keyReleaseEvent() methods are called immediately in that order. Or if, while holding Shift, I press a data key like 'X', my keyPressEvent is called twice, for the Shift key and then for Key_X with shift modifier status.

I am stumped as to how to get real-time notification of any modifier key. Something I tried was to add a raw event() handler and on any event whatever, to interrogate QApplication.queryKeyboardModifiers. It appears that even QApplication does not know about the modifier key pressed until they are released...?

Author:user405,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/19939608/how-to-avoid-delayed-notice-of-modifier-key-presses-qt-for-linux-and-windows
yy