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

Keyboard Multimedia Key Support? #930

Open
bai-yi-bai opened this issue Oct 20, 2024 · 0 comments
Open

Keyboard Multimedia Key Support? #930

bai-yi-bai opened this issue Oct 20, 2024 · 0 comments

Comments

@bai-yi-bai
Copy link

Hello, these are awesome libraries. I would like to implement USB HID keyboard multimedia keys, but I cannot get them to work. I am using the keyboard-example.py and keyboard.py file as a starting point. Is there some trick to this?

My project idea is to use a Pico W connected to a PC which doesn't have Ethernet, but does have Wi-Fi. I want to wake it up using usb-wake and then put it back to sleep. The Pico W will connect to an MQTT server and send keyboard commands based on the payload. The main multimedia keys I'd like to send are "Sleep", "Mute", and "Power". The host machine is Debian Bookworm running KDE.

I saw that on a subset of keycodes are defined in keyboard.py. I was able to add some additional keys, including KP_DOT = 99 #0x63, but not every value above 100 worked. I took line 85 of keyboard-example.py and changed it to keys.append(code) to keys.append(my_key) and set my_key to various integer values. I got the mapping from this gist

I tried several values:

  • #my_key = 102 # KEY_POWER 0x66
  • #my_key = 248 #define KEY_MEDIA_SLEEP 0xf8
  • #my_key = 239 #define KEY_MEDIA_MUTE 0xef
  • #my_key = 127 #define KEY_MUTE 0x7f

Unfortunately, none of these values worked, but I confirmed setting my_key = 4 did print the letter a, and so did many basic input keys and function keys. I plugged in a keyboard which has a mute key and used xev to examine the output.

a

KeyRelease event, serial 40, synthetic NO, window 0x7600001,
    root 0x1e3, subw 0x0, time 16518608, (89,64), root:(1920,1047),
    state 0x10, keycode 38 (keysym 0x61, a), same_screen YES,
    XLookupString gives 1 bytes: (61) "a"
    XFilterEvent returns: False

Mute

KeyRelease event, serial 52, synthetic NO, window 0x9000001,
root 0x1e3, subw 0x0, time 15116196, (108,91), root:(1939,1074),
    state 0x10, keycode 121 (keysym 0x1008ff12, XF86AudioMute), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

The mute key on the keyboard does mute system audio, but I cannot get the Pico to mute the PC.
The output states the keycode value should be 121, but when I try that, nothing comes through on xev. Comparing both events, I see that the keysim value is much larger for the mute key versus the a key.
I also don't have a keyboard with a power or sleep button on it, so I cannot verify what those key codes for real hardware are.

Any ideas?

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

1 participant