Media buttons in toolbar

Hello,

Is it possible to make multimedia buttons (play, pause ...) that will work the same as the multimedia buttons on the keyboard?
I use Spotify and foobar.

I don't think Windows has a built-in way to simulate pushing the media keys, at least not a reliable one, without writing something in C/C++/C#, etc. There doesn't seem to be a good way to do it from JScript or VBScript.

But it's something AutoHotkey can do fairly easily, by the look of it, so if you have (or install) AutoHotkey, you could make some Opus buttons which run AHK scripts that simulate the different buttons. That's the best I can think of.

Foobar lets you configure its hotkeys, I think, so you could also set up some keys in it that are easily sent via JScript/VBScript and the SendKeys method, but that wouldn't help with Spotify (unless it can do the same).

It should be possible with jscript and Opus scripting, see Toggle audio mute for example.

I couldn't find any reliable way to send the other media keys. Some threads on the net have key codes for next/prev track but also say they are unreliable, and I didn't see a code for play/pause anywhere.

For volume and muting, you can also do it via nircmd.exe, but I couldn't see a way for that to do the other media keys either. AutoHotkey can do them, though.

Googling around for the correct media play/pause keycode, this works for me to Play/Pause AIMP running minimized in the background:

function OnClick(clickData)
{
	var oShell = new ActiveXObject("WScript.Shell");
	oShell.SendKeys(String.fromCharCode(179));
}

There are various keycodes on the net, some of which seem to be wrong so hunting around and trying will be required.

I think this table should contain correct codes for media keys (just search "media" and "volume"): http://www.kbdedit.com/manual/low_level_vk_list.html
You'll have to convert hex to dec for example using page like https://www.rapidtables.com/convert/number/hex-to-decimal.html

2 Likes

I used several codes to try to go to the next track in JetAudio, but it didn't work, but the idea is great.

why you use it for AIMP as it has Global hotkeys???

You probably have to enable the global media keys in the JetAudio settings (but I don't use it so can't help further).

Just for testing since I already had AIMP installed.

I actually use AutoHotkey script for that, the reason being that I want to use the same key combo for all media players (including the web browser playing the media in the background) without having to configure every piece of app separately (I don't even know if web browsers support custom global keys -- but the standard media keys have wide support out of the box almost everywhere).

1 Like

Hello @bytespiller, you were very right, I had not enabled JetAudio's global keys, in fact, I did not even know that the program had a dedicated area for this, thank you very much.

Now with Ctrl + Shift + N I can go to the next track, even when JetAudio is not visible (it is minimized in the System Tray), but I have another question, how could I configure a button that simulates that key combination?

Maybe this can work to assign the multimedia key: in JetAudio click to assign a new key for Play/Pause and then click the Opus script button so that it sends its multimedia key, and see if the JetAudio picked it up (instead of Ctrl+Shift+N).

I did what you recommended but it didn't work, anyway thank you very much, you showed me the way, I'm going to ask a question here in the forum asking for help on key combinations.