XGETDEVICEKEYMAPPING(3)
π XGETDEVICEKEYMAPPING(3) β query or change device key mappings β¨
okay so bestie, welcome to section 3 of the manual, this is the XGetDeviceKeyMapping / XChangeDeviceKeyMapping page and it is lowkey one of the most useful little gremlins in the XInput toolbox π if you've ever wanted to peek at a device's key mapping or straight up rewrite it, this is your moment. periodt.
π NAME π
XGetDeviceKeyMapping, XChangeDeviceKeyMapping β query or change device key mappings π
πΈ SYNOPSIS πΈ
#include <X11/extensions/XInput.h>
KeySym *XGetDeviceKeyMapping( Display *display,
XDevice *device,
KeyCode first_keycode,
int keycode_count,
int *keysyms_per_keycode_return);
and here's who's who in the cast π«Ά:
displayβ the connection to the X server. your lil phone line to the server, basically.deviceβ the device whose key mapping is gonna be queried or modified. main character energy right here πfirst_keycodeβ the firstKeyCodeto be returned.keycode_countβ how manyKeyCodesto return or modify.keysyms_per_keycodeβ the number ofKeySymsperKeyCode.keysyms_per_keycode_returnβ the address of a variable where the number ofKeySymsperKeyCodegets handed back to you. it's giving "here's your receipt" π§Ύkeysymsβ the address of an array ofKeySyms.
β¨ DESCRIPTION β¨
so for the device you picked, the XGetDeviceKeyMapping request returns the symbols for the specified number of KeyCodes starting with first_keycode. easy. but there's a rule, bestie: the value you put in first_keycode must be greater than or equal to min_keycode as returned by XListInputDevices, or a BadValue error results π no cap. and also this expression has to be less than or equal to max_keycode as returned by XListInputDevices:
first_keycode + keycode_count - 1
if that's not the case, BadValue error, again. sorry, them's the rules π
the number of elements in the KeySyms list is:
keycode_count * keysyms_per_keycode_return
and KeySym number N, counting from zero, for KeyCode K has the following index in the list, counting from zero:
(K - first_code) * keysyms_per_code_return + N
the X server arbitrarily chooses the keysyms_per_keycode_return value to be large enough to report all requested symbols (server does what it wants, honestly, we respect it π
). a special KeySym value of NoSymbol is used to fill in unused elements for individual KeyCodes. and to free the storage returned by XGetDeviceKeyMapping, use XFree. do NOT forget to free it, leaking memory is not the vibe π«
if the specified device does not support input class keys, a BadMatch error will result.
XGetDeviceKeyMapping can generate a BadDevice, BadMatch, or BadValue error.
okay now the other one, the spicy one π₯
for the specified device, the XChangeDeviceKeyMapping request defines the symbols for the specified number of KeyCodes starting with first_keycode. the symbols for KeyCodes outside this range stay exactly as they were β untouched, unbothered, living their truth πΈ. the number of elements in keysyms must be:
num_codes * keysyms_per_keycode
the specified first_keycode must be greater than or equal to min_keycode returned by XListInputDevices, or a BadValue error results. and in addition, this next expression must be less than or equal to max_keycode as returned by XListInputDevices, or a BadValue error results:
first_keycode + num_codes - 1
KeySym number N, counting from zero, for KeyCode K has the following index in keysyms, counting from zero:
(K - first_keycode) * keysyms_per_keycode + N
the keysyms_per_keycode you specify can be chosen arbitrarily by the client, as long as it's large enough to hold all the desired symbols. a special KeySym value of NoSymbol should be used to fill in unused elements for individual KeyCodes. and here's a fun fact: it is legal for NoSymbol to appear in nontrailing positions of the effective list for a KeyCode π (yes, really, in the middle and everything, iconic). XChangeDeviceKeyMapping generates a DeviceMappingNotify event that gets sent to all clients that have selected that type of event. everybody finds out, it's a group chat notification fr fr π£
there is no requirement that the X server interpret this mapping. it is merely stored for reading and writing by clients. the server is just the storage unit here, not a hater, not a translator, just vibes π§
if the specified device does not support input class keys, a BadMatch error results.
XChangeDeviceKeyMapping can generate a BadDevice, BadMatch, BadAlloc, or BadValue error.
π©Ί DIAGNOSTICS π©Ί
BadDeviceβ an invalid device was specified. the specified device does not exist, or has not been opened by this client viaXOpenInputDevice. this error may also occur if the specified device is the X keyboard or X pointer device. (rude, but okay π)BadMatchβ this error may occur if anXGetDeviceKeyMappingorXChangeDeviceKeyMappingrequest was made specifying a device that has no keys. no keys, no mapping, no service πBadValueβ some numeric value falls outside the range of values accepted by the request. unless a specific range is specified for an argument, the full range defined by the argument's type is accepted. any argument defined as a set of alternatives can generate this error.BadAllocβ the server failed to allocate the requested resource or server memory. the server is tired, bestie, it needs a nap π
π SEE ALSO π
XSetDeviceButtonMapping(3)XSetDeviceModifierMapping(__3_)
go read those next, they're the sibling pages and they also ate π
and that's the whole page, bestie π«Ά go forth and map those keys responsibly.
this was the XGetDeviceKeyMapping(3) page from the XInput manual, dated 05/18/2026, and honestly? she served. mwah πβ¨ππ¦
π¦ where this page comes from
- fedora 44: libXi-devel 1.8.3-1.fc44 Β· MIT-open-group AND SMLNJ AND MIT
- fedora 44: libXi-devel 1.8.3-1.fc44 Β· MIT-open-group AND SMLNJ AND MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms