Skip to content
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

Canonical() suddenly returns KeyCode for F keys #611

Open
timojuez opened this issue Sep 19, 2024 · 1 comment
Open

Canonical() suddenly returns KeyCode for F keys #611

timojuez opened this issue Sep 19, 2024 · 1 comment

Comments

@timojuez
Copy link

On Pynput 1.7.7, the behaviour of canonical() changed so that now it caused an exception in my program.
pynput.keyboard.Listener().canonical(pynput.keyboard.Key.f1) used to return pynput.keyboard.Key.f1 but now returns <65470> of type KeyCode. This is missing the attribute name which would have returned "f1" and makes the key code clearly understandable. It seems that in e7964a6, an exception should be made for special keys.

@PiotrCzapla
Copy link

PiotrCzapla commented Oct 14, 2024

This breaks GlobalHotKeys listening on function keys.

Here is a workaround I've used to fix the issue :

class GlobalHotKeys2(pynput.keyboard.GlobalHotKeys):
    def __init__(
        self,
        hotkeys: dict[str, Callable],
        *args,
        **kwargs,
    ):
        super().__init__({}, *args, **kwargs)
        self._hotkeys = [
            HotKey([self.canonical(key) for key in HotKey.parse(key)], value)
            for key, value in hotkeys.items()
        ]

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

2 participants