Question

I want to get mapping-independent key codes, but documentation says that "keycode" in XKeyEvent structure depends on hardware and driver and I can't rely on it. How can I get some portable key codes like VK_* in Windows?

Was it helpful?

Solution

You want key syms, not key codes. See XKeycodeToKeysym() and /usr/include/X11/keysymdef.h

To be strictly correct (especially with internationalization) you need a whole bunch of code along the lines of http://git.gnome.org/browse/gtk+/tree/gdk/x11/gdkkeys-x11.c However, if you're using raw Xlib instead of a toolkit you probably don't care about this kind of thing (if you do you're in for years of work), and XKeycodeToKeysym() is good enough for US keyboards.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top