I'm having trouble getting key press events to work properly with the Shift key (it looks like Ctrl and Alt have this problem too, but most other keys work as expected). I'm overriding the keyPressEvent() method to try to detect when the Shift key is pressed. However, whenever i press the shift key i don't receive the event immediately. I only receive the event when i release the shift key or press another key on the keyboard.

The event for the shift key always fires immediately before the second event. Instead I want it to fire the instant I start holding down the shift key.


Does anyone know how to make this work, or perhaps a workaround that gives similar functionality?


Here's a snippet of the code i'm using:
Qt Code:
  1. void MainWindow::keyPressEvent ( QKeyEvent *event ) {
  2. using namespace Qt;
  3.  
  4. if ( event->isAutoRepeat() ) {
  5. event->ignore();
  6. return;
  7. }
  8. switch ( event->key() ) {
  9. //...
  10. //...
  11. //...
  12.  
  13. case Key_Shift:
  14. std::cout << "SHIFT PRESS" << std::endl;
  15. break;
  16. default:
  17. event->ignore();
  18. return;
  19. }
  20. }
To copy to clipboard, switch view to plain text mode