Skip to content

How to get mods keysym names from keysym numbers #272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ldrahnik opened this issue Apr 17, 2024 · 0 comments
Open

How to get mods keysym names from keysym numbers #272

ldrahnik opened this issue Apr 17, 2024 · 0 comments

Comments

@ldrahnik
Copy link

I needed to return for Shift dynamically Shift_L so I wrote this code and my question is whether part of the code marked as here could become part of this lib:

import Xlib.XK

mods_to_indexes_x11 = {
        "Shift": Xlib.X.ShiftMapIndex,
        "Lock": Xlib.X.LockMapIndex,
        "Control": Xlib.X.ControlMapIndex,
        "Mod1": Xlib.X.Mod1MapIndex,
        "Mod2": Xlib.X.Mod2MapIndex,
        "Mod3": Xlib.X.Mod3MapIndex,
        "Mod4": Xlib.X.Mod4MapIndex,
        "Mod5": Xlib.X.Mod5MapIndex
    }

if display and mod_name in mods_to_indexes_x11:

    mods = display.get_modifier_mapping()
    first_keycode = mods[mods_to_indexes_x11[mod_name]][0]
    if first_keycode:
        key = EV_KEY.codes[int(first_keycode) - 8]
        keysym = display.keycode_to_keysym(first_keycode, 0)

    	# here
        for key in Xlib.XK.__dict__:
            if key.startswith("XK") and Xlib.XK.__dict__[key] == keysym:
                return key[3:]
        # here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant