mvlabat
mvlabat

Reputation: 617

QKeyEvent handling non-latin layouts

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

Upvotes: 3

Views: 643

Answers (1)

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.

Upvotes: 2

Related Questions