I'm creating an on-screen keyboard for Linux integrated in a simple Window Manager. I'm currently using XCB, and now I want to make the fake keystrokes. Everything works fine using xtest extension, except for the detail that I can't get the true keycodes from the keysyms I want to put.
Currently I'm using xcb_key_symbols_get_keycode, and then I use xcb_key_symbols_get_keysym to know which modifier I need to get that symbol. This works fine when the configured keyboard is the USA one. But I have a spanish keyboard, and this call only returns the USA configurations. In spanish keyboards several symbols are obtained with the right alt (altgr), but the former calls doesn't seem to support it.
So, how can I get the keycodes needed to get any keysym? I presume that I need the XKB extensions, but I've been unable to find them for XCB, and I don't want to rewrite the whole window manager for XLib.
Thanks.
The following code will print the whole keycode-to-keysym mapping. It is equivalent to
xmodmap -pk
orxmodmap -pke
. That is, given any keycode, it gives you the keysyms associated to that keycode.(Except that it only shows keysym values, not keysym names, which you can find in
/usr/include/X11/keysymdef.h
or using Xlib'sXKeysymToString()
, and I don't think there exists an XCB port of that function, but you could write your own based onkeysymdef.h
.) (On my X server, there's 7 keysyms per keycode, and I'd like to know if the X server can support more than that...)If you want the opposite mapping (keysyms-to-keycodes), you may want
xcb_key_symbols_get_keycode()
, I don't know.And no, you don't need XKB to handle keyboard stuff. Most of the stuff you could possibly want can be done with the core X protocol, including but not limited to modifying the aforementioned keycode-to-keysym mapping, grabbing the keyboard, grabbing the mouse, sending keyboard/mouse input, using all 8 modifiers, and writing "pseudo Unicode" (ie. all the symbols you find in
keysymdef.h
, which I don't think is oficially Unicode but does contain a lot of stuff).