Question How do keyboard volume controls ACTUALLY work?

Mar 19, 2023
5
0
10
Hi.

First post. I've been a lurker for probably over 20 years, though! Put this under Software / Windows because I think it's a software question (although strongly hardware-typed!)

I'm aware that various keyboards have multimedia keys. Sometimes they're standalone buttons (or even knobs) and sometimes they're "modifiers" of existing keys (using an "Fn" key). My keyboard has no such keys, and no Fn key, but I thought it would be convenient to have the ability to mute volume or switch it up / down without messing around with the mouse.

There are software solutions, such as macro creation tools, but my areas of interest are the challenges of building a piece of hardware, making it USB, and 3D printing an enclosure.

Even this has been done before. I was partly inspired by several Arduino-based projects which claim to be successfully operating the Windows volume controls. I've done enough work to realise that there are actual keyboard scancodes which are sent to the HID driver, whose purpose is to modify volume, etc. What I believe is absent is the connection between the keyboard driver and the Windows volume controls. I'm increasingly confident that where folk have build the Arduino-based device to adjust their volume controls, it works because their keyboard driver relays the settings to the Windows audio mixer.

  • Can anyone confirm this, please? Or educate me?
  • The cherry on the cake (if I'm correct) would be if someone can point me to a generic keyboard driver which accepts the mulitimedia controller scancodes and sends them onwards to the mixer!
  • Otherwise, can anyone tell if the USB "mock keyboard" I'm building needs to advertise itself as a speficitype of HID, or something?

NB, I also know that I can buy a USB volume knob, but where'd be the fun in that?

Many thanks.
 
Huh?!
But arduino does have a keyboard library, you just program it to get an input on one of its pins when you press the physical button to send the desired keypress to windows.

Other than that you can look up 'windows keyboard hid whitepaper' on the googles, it's all standards so you can do something from the ground up.
 
Pretty much every USB keyboard should conform to the USB Human Interface Device Class. There's no "driver" you need to download, every computer or OS that has USB support built in should know how to interpret this.

As far as scan codes go: https://deskthority.net/wiki/Scancode

And if you want to know more about USB HID signaling (though you'd be better served finding the actual spec but I'm too lazy to find this)
 
Mar 19, 2023
5
0
10
Gezundheit.
But arduino does have a keyboard library, you just program it to get an input on one of its pins when you press the physical button to send the desired keypress to windows.
Other than that you can look up 'windows keyboard hid whitepaper' on the googles, it's all standards so you can do something from the ground up.
100% correct.
I've tried three different keyboard programs, from alledgedly working projects, using two differnt libraries. On in particular was even designed to work with a rotary encoder as a volume knob. None of them work for me. All of them will certainly transmit any keystroke combination I give them, EXCEPT multimedia keys.

For Arduino / C buffs, I distilled it down to what is essentially a one line program:

#include "DigiKeyboard.h"
#define KEY_VOLUME_DOWN 0x81 // on a multimedia keyboard
void setup() {
}
void loop() {
DigiKeyboard.sendKeyStroke(0);
DigiKeyboard.sendKeyStroke(KEY_VOLUME_DOWN);
DigiKeyboard.delay(1000);
}


This does not adjust my volume down. With modification, it will transmit any other string I give it. Just not modify the volume / mute.
 
Mar 19, 2023
5
0
10
Pretty much every USB keyboard should conform to the USB Human Interface Device Class.
Agreed. With the greatest of respect, I'm completely comfortable with how things "should" be. in this case, I believe this is how things actually are.

There's no "driver" you need to download, every computer or OS that has USB support built in should know how to interpret this.
Can't agree there. One end of the spectrum: why might this keyboard not need a driver? https://www.aliexpress.com/item/1005003712650471.html. How about: this one https://www.easyhindityping.com/korean-keyboard ?

OK. Closer to home, then. Historically, when the Windows key was added to the keyboard, there were about 180 million keyboards already in existence, which did not possess this key and absolutely zero computers or OS's which knew what to do with it. After that came the Fn key. After than came the Euro symbol. In the meantime, there are many keys in the last 70 years (F13 through F24, EXECUTE, STOP, etc.) which have disappeared from keyboards, but for which the scan codes still exist in the USB libraries.

For now, I remain quite convinced that different keyboards require different drivers.

Yes. I digested that as part of my degree course 30 years ago when keyboards had a serial interface and I built a 36 key keyboard for a disabled person who could only type with a single finger. "Windows" was a thing which may or may not catch on... I wrote a driver in Turbo Pascal ... might've been for DOS 6.
And if you want to know more about USB HID signaling (though you'd be better served finding the actual spec but I'm too lazy to find this)
Your admission ... But you still want the kudos for responding.
 
Can't agree there. One end of the spectrum: why might this keyboard not need a driver? https://www.aliexpress.com/item/1005003712650471.html. How about: this one https://www.easyhindityping.com/korean-keyboard ?
The Aliexpress one is a programmable keyboard. So either it's using custom scan codes or you need the "driver" to change what it's doing.

The Korean keyboard website is just telling you the obvious: download a Korean Unicode font and switch your keyboard layout to Korean, and now you can type up Korean as per the labels on the keyboard.

OK. Closer to home, then. Historically, when the Windows key was added to the keyboard, there were about 180 million keyboards already in existence, which did not possess this key and absolutely zero computers or OS's which knew what to do with it. After that came the Fn key. After than came the Euro symbol. In the meantime, there are many keys in the last 70 years (F13 through F24, EXECUTE, STOP, etc.) which have disappeared from keyboards, but for which the scan codes still exist in the USB libraries.

For now, I remain quite convinced that different keyboards require different drivers.
And I can tell you I've used more keyboards that I care to remember, some with foreign language layouts, and none of them require a specific driver to work. And if they didn't work as per the labels on the keys, it's because they're not using the correct keyboard layout and/or localization settings. Also considering I can use a recent keyboard just fine in Windows 98, with all of the keys functioning, including the media keys, that tells me the whole thing's been standardized for at least 2 decades.

Anyway, I dug a little into why what you're doing is not working, and it looks like the USB HID data format for sending keyboard data is a little more complicated than just sending a byte or two. I suggest researching how this is supposed to work rather than rely on some library that's probably hiding a bunch of its details from you for the sake of simplicity.
 
  • Like
Reactions: KDMcM
Mar 19, 2023
5
0
10
All comments equally valid, thank you.

Anyway, I dug a little into why what you're doing is not working, and it looks like the USB HID data format for sending keyboard data is a little more complicated than just sending a byte or two. I suggest researching how this is supposed to work rather than rely on some library that's probably hiding a bunch of its details from you for the sake of simplicity.

Yes there's absolutely no doubt that the Arduino superset (?) hides a lot of the low level material. The internet is teaming with projects which CLAIM to work. "Just download this into your Arduino..." Both these claim to work and have a bunch of commentators extolling the virtues:
https://learn.adafruit.com/trinket-usb-volume-knob/code
https://www.instructables.com/Digispark-Volume-Control/

I still can't quite imagine how any one driver can know how to handle all the keys which might be on a keyaboard. In a multimedia keyboard, for example how would the OS "know" which application to direct the Prev/Next/Pause buttons to, unless someone wrote a handler?

I've spotted a USB capture plugin for WireShark. If I get it to work, I'll report back.

Thanks for looking.
 
Mar 19, 2023
5
0
10
Anyway, I dug a little into why what you're doing is not working, and it looks like the USB HID data format for sending keyboard data is a little more complicated than just sending a byte or two. I suggest researching how this is supposed to work rather than rely on some library that's probably hiding a bunch of its details from you for the sake of simplicity.
Yes. To both. That keyboard module targetted at the Digispark can send only the regular (104?) scancodes and modifiers. As you suggest, sending MM keys is a slightly different protocol. The TrinketHIDcombo library can do it. Sending (normal) keys involves sending a code for the keyboard type (normal) the modifiers, the scancode, a zero and then the keys. Sending an MM key involves sending a code which indicates an MM keyboard, the format is a little different: we only send the key.

In fact, anyone who reckons they got this working with the DigiSpark keyboard module is talking out their hat. Naturally, I've been squinting at thsi for sufficiently long that I can't find my original source.

Again, thanks for the steer.
 
Last edited: