Each key produces a fixed keycode
in the range [7,255].
A list of keysyms
is associated with each KeyCode. The keysyms take into
account whether Shift keys etc have been pressed. The list of defined
KeySyms is in <X11/keysym.h>
. The mapping from keycodes to keysyms can be
changed server-wide. From the command line you can use
xmodmap -pk
to see the current mapping. The mapping that matches the keysym
to a string can be changed for just one client.
XLookUpString
is used to interpret a key event, producing both a keysym and an ASCII
string
To get the current mapping use
KeySym *XGetKeyBoardMapping(display,first_keycode,count,keysyms_per_keycode); int first_keycode; int count; /* how many keycodes to check */ int *keysyms_per_keycode; /*RETURN*/To change the mapping globally use
XChangeKeyBoardMapping(display,first_code,keysyms_per_code,keysyms,num_codes); KeySym *keysyms;to change it locally use
/* ALTER KEYBOARD MAPPING FOR A GIVEN KEYCODE */ /* WARNING : THIS MAY NOT BE IMPLEMENTED */ XRebindKeySym(display,keysym,list,mod_count,string,num_bytes) KeySym keysym; /* the keycode we wish to rebind */ KeySym *list; /*these are used as modifiers*/ int mod_count; char *string; /* string we wish to associate with it */ int nun_bytes; /* number of bytes in the string */To see which keycodes are to be used as modifiers, this structure is needed.
typedef struct{ int lock; int shift_a, shift_b; int control_a,control_b; int mod1_a, mod1_b; int mod2_a, mod2_b; int mod3_a, mod3_b; int mod4_a, mod4_b; int mod5_a, mod5_b: }XModifierKeys; GetModifierMapping(display,modifier_keys) ModifierKeys *modifier_keys; /*RETURN*/ SetModifierMapping(display,modifier_keys) ModifierKeys *modifier_keys; /* RETURN A CHAR STRING GIVEN AN ARRAY OF {KeyPressedEvent}s */ int XLookupString(event,buffer,num_bytes,keysym,status); nbytes) */ XKeyEvent *event; /* array of events to be interpreted*/ char *buffer; int numbytes; /* number of bytes in the char string */ KeySym *keysym; /*RETURN*/ XComposeStatus *status; /* default mapping is in /usr/lib/keymap.txt but user may */ /* specify his own in ~/.Xkeymap - see keycomp(1) */