Forward MediaKeys (e.g. Play/Pause)

VB-Audio Network Protocol and applications
Post Reply
arfmach
Posts: 9
Joined: Wed Jul 27, 2022 7:19 pm

Forward MediaKeys (e.g. Play/Pause)

Post by arfmach »

Hi there!

I'm almost always working in a setup where I have two computers, and I access the second one using Remote Desktop. I've managed to set up VBAN audio streams between them so I can use the main computer devices (mic, headphones) in the remote computer (e.g. for Teams calls). I often let a music app running in the main computer, and whenever I need to pause the music, I need to minimize the Remote Desktop session so I can press the Play/Pause key I have in my keyboard and then go back to the remote computer.

Is there any way to set VM / VBAN (/ MIDI?) between those two computers so when I press the Play/Pause in the remote session VM will forward it to the main computer and actually play/pause the music?

Thanks a lot.
Vincent Burel
Site Admin
Posts: 2020
Joined: Sun Jan 17, 2010 12:01 pm

Re: Forward MediaKeys (e.g. Play/Pause)

Post by Vincent Burel »

you can use VBAN-TEXT request to remote Voicemeeter for example (with MacroButtons). See user manual for details.
https://vb-audio.com/Voicemeeter/Voicem ... Manual.pdf
arfmach
Posts: 9
Joined: Wed Jul 27, 2022 7:19 pm

Re: Forward MediaKeys (e.g. Play/Pause)

Post by arfmach »

Hello.

I was able to set up MacroButtons and VBAN, and the target machine is receiving the command, as seen in the screenshot below.
VBAN-MEDIAPAUSE.png
VBAN-MEDIAPAUSE.png (55.52 KiB) Viewed 15945 times
But the music isn't paused in the target machine… Was it expected to work when that command is printed in VBAN window, or may there be anything else to set up?
Vincent Burel
Site Admin
Posts: 2020
Joined: Sun Jan 17, 2010 12:01 pm

Re: Forward MediaKeys (e.g. Play/Pause)

Post by Vincent Burel »

Such System commands are managed by the MacroButton app only. so this must be define in your MacroButton script.

Through VBAN-TEXT protocol, you have just to send the command to push a button:

Code: Select all

Command.Button[i].State = 1; 
Voicemeeter will forward the command to MacroButton application.

here is the list of command instructions you can use through VBAN-TEXT protocol to manage MacroButtons:

Code: Select all

Command.Button[i].State 0 or 1 Change Macro Button State 1
Command.Button[i].StateOnly 0 or 1 Change Button State only 1
Command.Button[i].Trigger 0 or 1 Change Trigger Enable State 1
Command.Button[i].Color 0 to 8 Change the Button Color 1
'i' is the button logical id.
arfmach
Posts: 9
Joined: Wed Jul 27, 2022 7:19 pm

Re: Forward MediaKeys (e.g. Play/Pause)

Post by arfmach »

Ok, I've set it up as you instructed.

This is the button setting in the source machine:
MacroButton-SourceMachine-SendButtonState.png
MacroButton-SourceMachine-SendButtonState.png (17.43 KiB) Viewed 15042 times
This is how I've set up the button in the target machine:
MacroButton-TargetMachine-SystemKeyPress.png
MacroButton-TargetMachine-SystemKeyPress.png (16.72 KiB) Viewed 15042 times
When I click the button directly in the target machine, it pauses/plays the music as expected, and the button state is reset to off (because of the PUSH mode).

But when I press the button in the source machine and it sends the command to the target machine, the System.KeyPress doesn't occur and the button in the target machine remains in "pressed" state (as if it was configured as a "2 Positions" button):
MacroButton-TargetMachine-Button0-State1.png
MacroButton-TargetMachine-Button0-State1.png (26.3 KiB) Viewed 15042 times
I've tried to add a "Command.Button[0].State = 0;" command after the "State = 1", and it makes the target machine button to go back to "unpressed" state (resembling the "PUSH" behavior), but the System.KeyPress still doesn't occur. I've also tried to move the System.KeyPress script from the "Button ON" request to the "Button OFF" request, but it yielded the same results. Also the same using "StateOnly" or "Trigger".
arfmach
Posts: 9
Joined: Wed Jul 27, 2022 7:19 pm

Re: Forward MediaKeys (e.g. Play/Pause)

Post by arfmach »

Another thing I've noticed is that, in VBAN screen, I can set the "IP Address From" / "IP Address To" with a hostname instead of a literal IP address, but not in MacroButtons, which only accepts IP addresses. Since my 2 machines are configured with DHCP in the LAN, the IP addresses can change, so it would be very useful if I could set MacroButtons with the hostname instead.
arfmach
Posts: 9
Joined: Wed Jul 27, 2022 7:19 pm

Re: Forward MediaKeys (e.g. Play/Pause)

Post by arfmach »

arfmach wrote: Mon Feb 12, 2024 7:38 pm Ok, I've set it up as you instructed.

This is the button setting in the source machine:
MacroButton-SourceMachine-SendButtonState.png

This is how I've set up the button in the target machine:
MacroButton-TargetMachine-SystemKeyPress.png
When I click the button directly in the target machine, it pauses/plays the music as expected, and the button state is reset to off (because of the PUSH mode).

But when I press the button in the source machine and it sends the command to the target machine, the System.KeyPress doesn't occur and the button in the target machine remains in "pressed" state (as if it was configured as a "2 Positions" button):
MacroButton-TargetMachine-Button0-State1.png

I've tried to add a "Command.Button[0].State = 0;" command after the "State = 1", and it makes the target machine button to go back to "unpressed" state (resembling the "PUSH" behavior), but the System.KeyPress still doesn't occur. I've also tried to move the System.KeyPress script from the "Button ON" request to the "Button OFF" request, but it yielded the same results. Also the same using "StateOnly" or "Trigger".
Ok, I've found out what is going on. When I'm in the remote session with full screen, almost all keys are forwarded to the remote machine, including MEDIAPLAY. So, if I click the MacroButton (or press the MEDIAPLAY shortcut to it) in the remote computer, it runs the script to send the command to my host machine, which in turn runs the System.KeyPress("MEDIAPLAY") script, but this keypress is forwarded again to the remote machine… I can confirm it if I exit full screen from remote session, since that will stop forwarding several keys, including MEDIAPLAY; so, in this scenario, the MacroButtons work as expected, I can click the button and it will play/pause the music, but I can't press MEDIAPLAY key in the remote machine, since it is not being forwarded and executes right in the host machine.

Maybe I need some script to use the Windows multimedia API and call Play/Pause directly to it, instead of relying on a keyboard media key. Any suggestions on that are very appreciated.

Thanks!
arfmach
Posts: 9
Joined: Wed Jul 27, 2022 7:19 pm

Re: Forward MediaKeys (e.g. Play/Pause)

Post by arfmach »

Well, I've finally managed to make it work! It needed some scripting (PowerShell), but at least it works.

This is the new setting of the button in the target machine (host):
MacroButtons-PlayPauseButton.png
MacroButtons-PlayPauseButton.png (18.1 KiB) Viewed 9674 times
This is the cmd script:

Code: Select all

@echo off
"%ProgramW6432%\PowerShell\7\pwsh.exe" "C:\Users\amach\OneDrive\Documentos\PowerShell\Scripts\PlayPause-Music.ps1"
And this is the PowerShell script:

Code: Select all

$pInvokeSignature = @'
[DllImport("user32.dll")]
public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo);
'@

Add-Type -MemberDefinition $pInvokeSignature -Namespace Win32Functions -Name KeyboardFunctions

$KEYEVENTF_EXTENDEDKEY = 1;
$VK_MEDIA_PLAY_PAUSE = 0xB3uy;

[Win32Functions.KeyboardFunctions]::keybd_event($VK_MEDIA_PLAY_PAUSE, 0uy, $KEYEVENTF_EXTENDEDKEY, 0)
The "keybd_event" does not forward the key to the Remote Desktop session, so it is always executed locally in the host machine.

The only complaint is that it opens a visible cmd.exe window (which vanishes after script execution finishes), so it would be GREAT if I could configure System.Execute() to run the window in a minimized state…
arfmach
Posts: 9
Joined: Wed Jul 27, 2022 7:19 pm

Re: Forward MediaKeys (e.g. Play/Pause)

Post by arfmach »

The only complaint is that it opens a visible cmd.exe window (which vanishes after script execution finishes), so it would be GREAT if I could configure System.Execute() to run the window in a minimized state…
@Vincent, could you please estimate if it is possible to improve the System.Execute() call to have an option for running the command in a minimized window?

Thanks a lot!
Post Reply