keysymdef

raw JSON →
1.2.0 verified Fri May 01 auth: no python

X11 keysym data for Python, providing a mapping from keysym names (like 'XK_a', 'XK_Return') to their integer codes and vice versa. Current version: 1.2.0. Maintained as a small utility library, releases are infrequent.

pip install keysymdef
error TypeError: 'module' object is not iterable
cause Attempting to iterate over keysymdef directly (e.g., for key in keysymdef).
fix
Use keysymdef.all_names() or list(keysymdef.keys()) to get a list of keys.
error KeyError: 'XK_unknown'
cause Keysym name not present in the mapping (typo or missing keysym).
fix
Verify the keysym name from X11 documentation. Use 'key in keysymdef' to check.
gotcha The keysymdef module is not a dict but a module that implements __getitem__ and __len__. Avoid iterating directly with for key in keysymdef: it raises TypeError. Use keysymdef.all_names() or list(keysymdef.keys()) instead.
fix Use keysymdef.all_names() or list(keysymdef.keys()) to iterate keys.
gotcha Keysym names are case-sensitive and must be exactly as in X11 headers (e.g., 'XK_a' not 'xk_a' or 'a').
fix Always use the canonical keysym name with 'XK_' prefix if applicable.
deprecated The .keysym() method is not part of the original API (it was added in 1.2.0). If you are using older versions, reverse lookup may not be available.
fix Upgrade to >=1.2.0 or implement your own reverse mapping.
gotcha The module does not include all possible X11 keysyms; only those defined in X11/keysymdef.h. Some vendor-specific or custom keysyms may be missing.
fix Check via 'key in keysymdef' before using a keysym.

Basic usage: treat the module as a dict mapping X11 keysym names to codes, and use keysym() for reverse lookup.

import keysymdef

# Get keysym code for 'XK_a'
code = keysymdef['XK_a']  # 97
print(code)

# Get name from code
name = keysymdef.keysym(97)  # 'XK_a'
print(name)

# List all keysym names
print(len(keysymdef))  # thousands of entries