pynput
pynput copied to clipboard
How to get the pressed key using GlobalHotkeys?
I need to get the pressed key of GlobalHotkeys so that I can filter key combinations. Using Listener objects you can do this by passing on_press and on_release parameters. But if I do it in GlobalHotkeys it's giving me an error. How do I do this?
# MyHotkeys.py
class MyHotkeys(GlobalHotKeys):
def __init__(self, hotkeys):
super().__init__(hotkeys, darwin_intercept=self.my_filter)
def my_filter(self, t, e):
pass
# main.py
def my_func():
# How to get key here?
print("hello world")
my_hotkeys = MyHotkeys ({"<ctrl>+i": my_func})
@bd-charu hey, did you figure it out?
Thank you for your report.
GlobalHotkeys
derives from a keyboard listener and accepts the same arguments. Have you tried simply passing darwin_intercept=some_function
to its constructor?