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

Multimedia keys on Linux #20

Open
boppreh opened this issue Nov 14, 2016 · 4 comments
Open

Multimedia keys on Linux #20

boppreh opened this issue Nov 14, 2016 · 4 comments

Comments

@boppreh
Copy link
Owner

boppreh commented Nov 14, 2016

Linux doesn't seem to emit any events for multimedia keys. In Windows they were already weird because of their null scan code, but in Linux literally nothing happens.

This should be fixed somehow.

@ahogen
Copy link

ahogen commented Aug 6, 2017

Linux doesn't seem to emit any events for multimedia keys.

Does this mean you can't capture a multimedia button press, or you can't send a key press?

Looking at an application where I want to send a multimedia key (not capture) so would this issue affect my use? Thanks!

@boppreh
Copy link
Owner Author

boppreh commented Aug 6, 2017

It's been a while, let me check...

@boppreh
Copy link
Owner Author

boppreh commented Aug 6, 2017

TL;DR: Yes, it works, as long as you know the scan code.

I just tried with a Fedora 25 live CD.

Pressing FN+F5 (brightness down in my laptop keyboard) results in Fedora muting the microphone. Not our fault here, but just to let you know.

keyboard correctly captured that key press with scan code of 190, even if the name was "unknown". You can check this by running python -m keyboard, which should print each key event as a small JSON object. And even better, the scan code was sufficient to reproduce the event.

This allowed me to record and replay the key presses, with the microphone correctly muting and unmuting as with a normal key press:

# python -m keyboard > events.txt
[...recording...]

# python -m keyboard < events.txt
[...replaying...]

If you are trying to emulate media keys that you don't have, I don't know what would happen. If you do try, please report back here and I'll note down for future users.

@ahogen
Copy link

ahogen commented Aug 6, 2017

Okay great. I'll go ahead and mess around with it then. Thanks for doing that little bit of research! I appreciate it!

I was looking at some of the Windows keyboard codes here, with the volume up/down/mute buttons being of particular interest.

Constant/value Description
VK_VOLUME_MUTE
0xAD
Volume Mute key
VK_VOLUME_DONE
0xAE
Volume Down key
VK_VOLUME_UP
0xAF
Volume Up key
VK_MEDIA_NEXT_TRACK
0x80
Next track key
VK_MEDIA_PREV_TRACK
0x81
Previous Track key
VK_MEDIA_PLAY_PAUSE
0x83
Play/Pause Media key

And then there are the keyboard/keypad codes defined by the USB Implementers Forum here (pg. 56).

Usage ID
(Dec)
Usage ID
(Hex)
Usage Name
127 0x7F Mute
128 0x80 Volume Up
129 0x81 Volume Down

Maybe between the two of those I get get something working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants