Próbowałeś może użyć coś w tym stylu
from pynput import keyboard
def activate(key):
print(f'Key pressed: {key}')
def quit():
h.stop()
with keyboard.GlobalHotKeys({
'<ctrl>+a': lambda: activate('a'),
'<ctrl>+b': lambda: activate('b'),
'<ctrl>+c': quit}) as h:
h.join()
lub
from pynput import keyboard
def activate(key):
print(f'Key pressed: {key}')
def quit():
h.stop()
with keyboard.GlobalHotKeys({
'a': lambda: activate('a'),
'b': lambda: activate('b'),
'<ctrl>+c': quit}) as h:
h.join()
lub ewentualnie tak jak napisał @adrian17, użyj
zwykłego Listenera