-
Notifications
You must be signed in to change notification settings - Fork 428
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
Capture the activation of a hotkey while other keys are being pressed #624
Comments
Here's some semi-pseudocode that worked for me. keybind = set() # I converted the keybind I want to block to a set of scan codes
pressed_keys = set()
def on_key_event(event):
if event.event_type == "down":
pressed_keys.add(event.scan_code) # add key to active keys
elif event.event_type == "up":
pressed_keys.discard(event.scan_code) # remove key from active keys
return True
# block our hotkey regardless of any additional keys
if keybind.issubset(pressed_keys): # if keybind is among pressed keys
print("keybind blocked")
return False
return True
keyboard.hook(on_key_event, suppress=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, I am trying to register a hotkey like shift+1 that should be suppressed even when other keys are pressed.
As stated here it's by design, that any additional keys that are being pressed at the same time will not trigger the
add_hotkey
callback.Which means that shift+1+k will not activate.
I've been trying to get this working for hours now and didn't find a solution.
I tried to focus on
hook
andis_pressed
. Here are two examples:keyboard.hook
(and related) withsuppress=True
and returning either True or False in the callback.This does only work if you hold down the keys. The initial keypress e.g. shift+1 will still pass.
keyboard.is_pressed("shift+1")
does register the hotkey flawlessly, however it appears there's no option to actually suppress the event?Any idea is highly appreciated!
The text was updated successfully, but these errors were encountered: