How to convert X11 KeyCode or KeySym to scan code

1.4k views Asked by At

I need to get scan codes of keyboard buttons (or any other codes) in layout-independent way. More specific, let's say I have QEditText and catching keystrokes from it. Now I'm starting to press a single button, and when the layout is English it has keycode=X, then I'm switching layout to Russian (German, French, whatever) and keycode becomes Y - but the physical button is the same. So I need to know code of that physical button, how to do this?

1

There are 1 answers

0
Kuba On

I am not sure if you will be able to do this only from code itself by some qt/x11 methods, but there is a tool that helps in similar situations: xbindkeys. You can read more here: https://unix.stackexchange.com/questions/91355/shortcut-keys-that-are-independent-to-keyboard-layout

If you can't use xbindkeys, you can still check its code and see how the author achieved this.