QKeyEvent handling non-latin layouts

583 views Asked by At

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

1

There are 1 answers

2
Kuba hasn't forgotten Monica On BEST ANSWER

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 Roman W.

If you intend to refer to physical keys, you can try using QKeyEvent::nativeScanCode() and/or QKeyEvent::nativeVirtualKey(). These values are platform-dependent, of course.