boppreh / keyboard

Hook and simulate global keyboard events on Windows and Linux.
MIT License
3.77k stars 433 forks source link

[Win] Media keys not working in hotkeys #544

Open wolfinabox opened 2 years ago

wolfinabox commented 2 years ago

With the following code:

import keyboard as kb

keys=["space","volume mute",
"volume down",
"volume up",
"next track",
"previous track",
"play/pause media"]

for key in keys:
    kb.add_hotkey(key,lambda key=key:print(f'{key} pressed!'))

while True:
    event = kb.read_event()
    print(event)

Activating any of the listed media keys are read as events in the loop:

KeyboardEvent(volume up down)
KeyboardEvent(volume up up)
...etc

(Similar output for new_core branch) But the assigned hotkeys above are not triggered. Just to make sure hotkeys are working in general, I added space, and that does trigger the hotkey when pressed. Tested on current pypi version, as well as new_core branch 0bd72225fdb60fe3679cd90bb30e56eaae2cc183 Tested on Win10 desktop with Steelseries Apex 7 w/ "scroll-wheel" volume control, and Win10 Asus laptop with dedicated vol up/down keys Tried:

Possibly related to the Windows volume/media control popup? That shows up even if I set suppress=True in the hotkey (even when running as admin) image

dyhe83 commented 2 years ago

I am facing the same issue, can anyone help??

LegendaryFire commented 1 year ago

Also experiencing an issue with volume control.