0
votes

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...?

1

1 Answers

0
votes

I believe this is not a real problem. The symptoms are seen while testing in a virtual machine under Parallels. Parallels has a number of its own special key shortcuts such as control-command-F to enter full-screen mode.

What I am seeing is consistent with Parallels Desktop "sitting on" any modifier key until it is sure that I am not trying to use one of its special shortcuts. Then when it sees that this is not the case, for example when I release the modifier key, or press a data key, it says, ok, virtual system, here's all the keyboard events for you.