Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Wrestling with ControlSend {Media_Play_Pause} Foobar2000.


  • Please log in to reply
4 replies to this topic
MsgBox
  • Members
  • 204 posts
  • Last active: Jan 05 2011 01:40 AM
  • Joined: 17 Nov 2005
My challenge (let's be positive) is to ControlSend {Media_Play_Pause} to Foobar2000 when it's "not" an active window.
Example:
MyPlay/PauseButton::        ; For completeness.
IfWinExist, %FoobClass%
	{
		IfWinNotActive,%FoobClass%
		{
			ControlSend,ahk_parent,{Media_Play_Pause}			
			Return
		}
		Send, {Media_Play_Pause}
	}
Return
When the window is inactive, the ControlSend commad doesn't work.
When active, the Send command does.

I can ControlSend other key combinations.
In this example, "c" tells Foobar to "play" and does, when minimized or behind another window.
IfWinExist, %FoobClass%
	{
		IfWinNotActive,%FoobClass%
		{
			ControlSend,ahk_parent,c			
			Return
		}
		Send, {Media_Play_Pause}
	}
Return

This is what I am using now, but I don't like the fact that Foobar flashes onscreen every time I want to pause it.
IfWinExist, %FoobClass%
	{
		IfWinNotActive,%FoobClass%
		{
			WinActivate
			Send, {Media_Play_Pause}
			WinMinimize
			Return
		}
		Send, {Media_Play_Pause}
	}
Return
Any thoughts or suggestions will be very much appreciated.

Thanks.

MsgBox
  • Members
  • 204 posts
  • Last active: Jan 05 2011 01:40 AM
  • Joined: 17 Nov 2005
Since I first posted this I have been playing with ControlSend and the Media keys with Media Player Classic with the same result, "a big fat ZERO".

So I suppose the question is, can you ControlSend media keys? {Media_Play_Pause}{Media_Stop}{Media_Next} etc

As I said (above), if I swap the media keys for the programs keyboard shortcut, then the key is (control)sent.
And if the window is active, I can Send the media keys.

I haven't found anything in the manual that sheds any light, and a search on the forum came up nothing useful, so if someone will confirm or deny the above question I will know what do do next.

Thanks.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004

can you ControlSend media keys? {Media_Play_Pause}{Media_Stop}{Media_Next} etc

Since each such key has a virtual key code, they should get sent properly. The problem may lie in how the receiving program interprets them: it's possible that some applications process such keystrokes in a way different from other keystrokes, which may explain why ControlSend has no effect when sending media keys to certain apps.

If you need to automate something without activating its window -- and ControlSend, ControlClick, and other methods don't work -- you could try Rajat's SendMessage Tutorial.

MsgBox
  • Members
  • 204 posts
  • Last active: Jan 05 2011 01:40 AM
  • Joined: 17 Nov 2005

If you need to automate something without activating its window -- and ControlSend, ControlClick, and other methods don't work -- you could try Rajat's SendMessage Tutorial.

Before I posted I had a look at it, and got quite scared! However, I did give it another go and started to make progress.

In the mean time, a search on google for Foobar & Sendmessage found this: (Documented for future searches.)

The name if the main window is not standardized, so it is not documented anywhere. The same goes for details about what messages the main window has to handle. Controling foobar2000 by sending window messages to the main window is not supported and strongly discouraged.

The prefered way to control foobar2000 is by using command line commands or a custom plugin. As far as I remember, there are already such plugins, the newest one seems to be foo_rmx (just search the 3rd party plugins forum for the thread).


Another search:

Finaly, if you want a full list of commands, try this:
"C:\Program Files\foobar2000\foobar2000.exe" /?

This produces two message boxes

---------------------------
Commandline help
---------------------------
Available switches:
/add, /play, /pause, /playpause, /prev, /next, /rand, /stop, /exit, /show, /hide, /config
/command:

, /playlist_command:, /playing_command:
---------------------------
OK
---------------------------


---------------------------
Commandline help
---------------------------
Usage:

/tag:help - displays this message

/tag:[;;...] [ ...]

Commands:

=
Sets field to , e.g. "/tag:title=test ".
You can erase particular field by specifying empty value, e.g. "/tag:comment= ".
You can also specify multiple values by separating them with \ character, e.g. "/tag:artist=name1\name2 ".
AUTOTRACKNUMBER
Sets TRACKNUMBER field of multiple files according to their order in commandline.
E.g. "/tag:AUTOTRACKNUMBER " will assign TRACKNUMBER=1 to , 2 to and 3 to .
FORMAT::
Formats using ; see title formatting manual for more info how to use it.
E.g. "/tag:FORMAT:COMMENT:"%ARTIST% - %TITLE%" ".
GUESS::
Guesses field values using , according to .
To perform "guess values from filename" action, use "/tag:GUESS::%_FILENAME% ".
E.g. "/tag:GUESS:"%TRACKNUMBER%. %TITLE%":%_FILENAME% ".

---------------------------
OK
---------------------------

The long and short of it is that I can now press Play/Pause on my keyboard whether Foobar is active or not and have it work.
Run C:\Program Files\foobar2000\foobar2000.exe /playpause
Another useful quote:

foobar2000 can execute any command listed under Preferences/Core/Main menu items via "/command:".


Thanks.

MsgBox
  • Members
  • 204 posts
  • Last active: Jan 05 2011 01:40 AM
  • Joined: 17 Nov 2005
Update:

I have found out that you can use multmedia keys in the keyboard shortcut section of Prefs in FooBar2000. Also, there IS a command for Play/Pause! :roll: (...it wasn't there the first time I looked! ;))
1+1=2, Excellent!

After setting up the shorcuts and using the global option, the damn thing wouldn't work!

Sending {SC122} {A_ThisHotkey} or {Media_Play_Pause} had no effect.
However, {VKB3} did the trick.

Also, there is the added bonus, I can control play back when Foobar is in the system tray. I couldn't even do that with the MS keyboard software installed.

All in all, this solution has worked out better than expected for me, especially the above bonus, so now I'm a happy chap. :)