From 26fe001ada956c0ad023ea0e3aa3c7dded3526ad Mon Sep 17 00:00:00 2001 From: Adam Lewis <23342526+Adam-D-Lewis@users.noreply.github.com> Date: Tue, 10 Jun 2025 02:04:14 -0500 Subject: [PATCH] handle case when alt gr not defined in keyboard layout --- lib/pynput/_util/xorg.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/pynput/_util/xorg.py b/lib/pynput/_util/xorg.py index 52995f3..163d484 100644 --- a/lib/pynput/_util/xorg.py +++ b/lib/pynput/_util/xorg.py @@ -95,6 +95,10 @@ def _find_mask(display, symbol): modifier_keycode = display.keysym_to_keycode( Xlib.XK.string_to_keysym(symbol)) + if modifier_keycode == 0: + # No such modifier key defined in the display + return 0 + for index, keycodes in enumerate(display.get_modifier_mapping()): for keycode in keycodes: if keycode == modifier_keycode: @@ -320,8 +324,13 @@ def keyboard_mapping(display): if not normalized: continue + group_states = [False, True] + if group_mask == 0: + # No altgr keysyms, so we can skip this group + group_states = [False] + # Iterate over the groups to extract the shift and modifier state - for groups, group in zip(normalized, (False, True)): + for groups, group in zip(normalized, group_states): for keysym, shift in zip(groups, (False, True)): if not keysym: continue