What is the way to handle non-latin keys pressed with Qt?
For example, for 'W' key pressed QKeyEvent::key() returns 87, but for 'Ц' - the same key in the russian layout - it returns 1062.
So I can't use constants like Qt::Key_W for checking which key has been pressed: they won't work if a user switches the layout.
Thank you
The meaning of a key depends on the currently selected layout. What you observe is correct. If you pressed that key in any other application, you wouldn't get a W, but a Ц (C).
A given key means
Qt::Key_W
only if it's in a layout that produces the RomanW
.If you intend to refer to physical keys, you can try using
QKeyEvent::nativeScanCode()
and/orQKeyEvent::nativeVirtualKey()
. These values are platform-dependent, of course.