Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt LEFT CTRL Key Code

In Qt's QKeyEvent I can check whether Ctrl was pressed by checking if ev->key() is Qt::Key_Control. But how can I distinguish between the left and right Ctrl keys?

I also need the same thing for Alt and Shift keys.

like image 874
Dipro Sen Avatar asked Jul 01 '12 15:07

Dipro Sen


2 Answers

There is no way to do this using pure Qt methods, as far as I know.

Depending on your platform, however, you might be able to distinguish between the keys using the QKeyEvent::nativeScanCode() method instead of QKeyEvent::key().

For example, on Windows you should be able to test which Ctrl key was pressed as follows:

if (event->nativeScanCode() == VK_LCONTROL) {
  // left control pressed
} else if (event->nativeScanCode() == VK_RCONTROL) {
  // right control pressed
}
like image 183
houbysoft Avatar answered Sep 20 '22 04:09

houbysoft


According to the Qt Namespace Reference, the enum Qt::Key has a different value for Qt::Key_Alt and Qt::Key_AltGr.

However, enum Qt::KeyboardModifier and enum Qt::Modifier don't see the pair of keys as different modifiers.

(note: I would have posted this as a comment but I don't have enough rep. yet)

like image 32
Sparkler Avatar answered Sep 17 '22 04:09

Sparkler