Hello,
I'm working on a cross platform application in which user must be able to check whether a particular key is pressed or not.

So, I create a map of keys like this:
Qt Code:
  1. std::unordered_set<int> pressedKeys;
To copy to clipboard, switch view to plain text mode 
... and store each key when is pressed
Qt Code:
  1. void MyAapp::keyPressEvent(QKeyEvent *e) {
  2. e->accept();
  3. mymutex->lock();
  4. qDebug() << "+key:" << e->key() << "=" << e->text() <<", nativeVirtualKey:" << e->nativeVirtualKey() <<", isAutoRepeat:" << e->isAutoRepeat() <<", modifiers" << e->modifiers();;
  5. if(!e->isAutoRepeat()){
  6. // Note that if the event is a multiple-key compressed event that is partly due to auto-repeat,
  7. // isAutoRepeat() function could return either true or false indeterminately.
  8. if( e->modifiers() & Qt::ShiftModifier )
  9. {
  10. pressedKeys.insert(Qt::Key_Shift);
  11. }else{
  12. pressedKeys.erase(Qt::Key_Shift);
  13. }
  14. if( e->modifiers() & Qt::ControlModifier )
  15. {
  16. pressedKeys.insert(Qt::Key_Control);
  17. }else{
  18. pressedKeys.erase(Qt::Key_Control);
  19. }
  20. if( e->modifiers() & Qt::AltModifier )
  21. {
  22. pressedKeys.insert(Qt::Key_Alt);
  23. }else{
  24. pressedKeys.erase(Qt::Key_Alt);
  25. }
  26. if( e->modifiers() & Qt::MetaModifier )
  27. {
  28. pressedKeys.insert(Qt::Key_Meta);
  29. }else{
  30. pressedKeys.erase(Qt::Key_Meta);
  31. }
  32. pressedKeys.insert(e->key());
  33. }
  34. mymutex->unlock();
  35. }
To copy to clipboard, switch view to plain text mode 
... and delete a key when key is released:
Qt Code:
  1. void MyApp::keyReleaseEvent(QKeyEvent *e) {
  2. e->accept();
  3. mymutex->lock();
  4. qDebug() << "-key:" << e->key() << "=" << e->text() <<", nativeVirtualKey:" << e->nativeVirtualKey() <<", isAutoRepeat:" << e->isAutoRepeat() <<", modifiers" << e->modifiers();;
  5. if(!e->isAutoRepeat()){
  6. pressedKeys.erase(e->key());
  7. if( e->modifiers() & Qt::ShiftModifier )
  8. {
  9. pressedKeys.insert(Qt::Key_Shift);
  10. }else{
  11. pressedKeys.erase(Qt::Key_Shift);
  12. }
  13. if( e->modifiers() & Qt::ControlModifier )
  14. {
  15. pressedKeys.insert(Qt::Key_Control);
  16. }else{
  17. pressedKeys.erase(Qt::Key_Control);
  18. }
  19. if( e->modifiers() & Qt::AltModifier )
  20. {
  21. pressedKeys.insert(Qt::Key_Alt);
  22. }else{
  23. pressedKeys.erase(Qt::Key_Alt);
  24. }
  25. if( e->modifiers() & Qt::MetaModifier )
  26. {
  27. pressedKeys.insert(Qt::Key_Meta);
  28. }else{
  29. pressedKeys.erase(Qt::Key_Meta);
  30. }
  31. }
  32. mymutex->unlock();
  33. }
To copy to clipboard, switch view to plain text mode 

Everything is perfect.
To be a cross platform I use Qt Key-enum values for keys (http://doc.qt.io/qt-4.8/qt.html#Key-enum).

The problem appears when I press a sequence like this:
(notation: + is keyPressEvent, - is keyReleaseEvent):
user press SHIFT
+key: 16777248 = "" , nativeVirtualKey: 16 , isAutoRepeat: false , modifiers QFlags<Qt::KeyboardModifiers>(ShiftModifier)
user press "2", but because SHIFT is pressed, then Qt returns Qt::Key_At "@"
+key: 64 = "@" , nativeVirtualKey: 50 , isAutoRepeat: false , modifiers QFlags<Qt::KeyboardModifiers>(ShiftModifier)
-key: 64 = "@" , nativeVirtualKey: 50 , isAutoRepeat: true , modifiers QFlags<Qt::KeyboardModifiers>(ShiftModifier)
... keep pressing SHIFT+2 = "@" but in fact user press "2" key
+key: 64 = "@" , nativeVirtualKey: 50 , isAutoRepeat: true , modifiers QFlags<Qt::KeyboardModifiers>(ShiftModifier)
release SHIFT
-key: 16777248 = "" , nativeVirtualKey: 16 , isAutoRepeat: false , modifiers QFlags<Qt::KeyboardModifiers>(NoModifier)
now the key is "2" but the original key "@"is in map as pressed
+key: 50 = "2" , nativeVirtualKey: 50 , isAutoRepeat: false , modifiers QFlags<Qt::KeyboardModifiers>(NoModifier)
-key: 50 = "2" , nativeVirtualKey: 50 , isAutoRepeat: true , modifiers QFlags<Qt::KeyboardModifiers>(NoModifier)
...
I do not like the fact that Qt return "@" as a key instead of "2".
One of the flaw is in the example above: the "@" key remains in pressedKeys map as pressed even after the key is actually released.
I want to receive the real key, not the combination.
And I need in cross platform way.

Remember that user must be able to check if a specific key is pressed. For this I check if key is in pressedKeys map and return true/false. User use Key-enum values.

Any ideas?
Thanks!