Changing MPC from Playing to Paused Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Johnny McQuack
Posts: 5
Joined: 12 Feb 2017, 05:38

Changing MPC from Playing to Paused

26 Jun 2017, 11:49

Hey, I'm trying to get a script to minimize Media Player Classic, and I also want to pause it if it's playing.

This is what I came up with:

Code: Select all

if #WinExist, ahk_class MediaPlayerClassicW, Playing
{
^Numpad4::
WinMinimize, ahk_class MediaPlayerClassicW
send {Media_Play_Pause}
return
}
else
#ifWinExist, ahk_class MediaPlayerClassicW, Paused
{
^Numpad4::
WinMinimize, ahk_class MediaPlayerClassicW
return
}
Is there a way to simply change the state from Playing to Paused without sending the play/pause key? Because sending that key can conflict with other programs I might have open at the same time.

Thanks in advance!
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Changing MPC from Playing to Paused  Topic is solved

26 Jun 2017, 12:02

Code: Select all

;Multiple instances
^Numpad4::
for process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process"){
		PostMessage, 0x0111, 888,,, % "ahk_pid " process.ProcessId " ahk_class MediaPlayerClassicW"
		WinMinimize, % "ahk_pid " process.ProcessId " ahk_class MediaPlayerClassicW"
	}
Return

;Single instance
^Numpad4::
	PostMessage,0x0111,888,,,ahk_class MediaPlayerClassicW
	WinMinimize, ahk_class MediaPlayerClassicW
Return
Johnny McQuack
Posts: 5
Joined: 12 Feb 2017, 05:38

Re: Changing MPC from Playing to Paused

26 Jun 2017, 12:06

Nextron wrote:

Code: Select all

^Numpad4::
for process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process"){
		PostMessage, 0x0111, 888,,, % "ahk_pid " process.ProcessId " ahk_class MediaPlayerClassicW"
		WinMinimize, % "ahk_pid " process.ProcessId " ahk_class MediaPlayerClassicW"
	}
Return
Thanks! That surely works, how can I just minimize it in case it's not playing though?

Usually I would figure that out and do the rest myself but... This looks like gibberish to me, I have absolutely no idea what you did there.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Changing MPC from Playing to Paused

26 Jun 2017, 12:06

Many Media Player Classic tips here:
Will Pay for heavily customized Skype AHK Script for disabled sister! - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 36#p130036

Code: Select all

;play/pause (see 'View, Options..., Player, Keys' for more ID numbers):
SendMessage, 0x111, 887,,, ahk_class MediaPlayerClassicW ;MEDIA_PLAY
SendMessage, 0x111, 888,,, ahk_class MediaPlayerClassicW ;MEDIA_PAUSE
SendMessage, 0x111, 889,,, ahk_class MediaPlayerClassicW ;MEDIA_PLAY_PAUSE (toggle)
[EDIT:] You could repeatedly retrieve the timestamp, via a Loop or SetTimer, and if doesn't change, minimise the window. Or check the status text.

Code: Select all

q:: ;media player classic - get time/status
ControlGetText, vTime, Static2, ahk_class MediaPlayerClassicW
ControlGetText, vStatus, Static3, ahk_class MediaPlayerClassicW ;e.g. blank/Opening.../Playing/Paused
MsgBox, % vTime "`r`n" vStatus
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Johnny McQuack
Posts: 5
Joined: 12 Feb 2017, 05:38

Re: Changing MPC from Playing to Paused

26 Jun 2017, 12:18

jeeswg wrote:[EDIT:] You could repeatedly retrieve the timestamp, via a Loop or SetTimer, and if doesn't change, minimise the window. Or check the status text.

Code: Select all

q:: ;media player classic - get time/status
ControlGetText, vTime, Static2, ahk_class MediaPlayerClassicW
ControlGetText, vStatus, Static3, ahk_class MediaPlayerClassicW ;e.g. blank/Opening.../Playing/Paused
MsgBox, % vTime "`r`n" vStatus
return
I am very sorry but I didn't understand a word of what you said, what exactly is that supposed to do?

Regardless, I managed to do something with what you said before the edit.

Code: Select all

^Numpad4::
SendMessage, 0x111, 888,,, ahk_class MediaPlayerClassicW ;MEDIA_PAUSE
WinMinimize, ahk_class MediaPlayerClassicW
return
It seems to always keep MPC minimized and paused, which is essentially what I was looking for, and no need for the "else" part I was originally adding. Thanks!

EDIT: Also, am I supposed to understand any of the "SendMessage, 0x111, 888,,," part or is it just something MPC related?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Changing MPC from Playing to Paused

26 Jun 2017, 12:26

- 'change the state from Playing to Paused' [set state]
- 'pause it if it's playing' / 'in case it's not playing' [get state]
I've tried to answer both those questions.

My later post gives you info on MPC (timestamp and playing status).

The SendMessage line sends WM_COMMAND (0x111), a message used in many programs to invoke a menu item command, or sometimes other commands also.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Changing MPC from Playing to Paused

26 Jun 2017, 12:28

Johnny McQuack wrote:It seems to always keep MPC minimized and paused, which is essentially what I was looking for, and no need for the "else" part I was originally adding. Thanks!
;)
Also, am I supposed to understand any of the "SendMessage, 0x111, 888,,," part or is it just something MPC related?
SendMessage sends a message to a process. It depends on the process whether it is designed to understand/listen to such message. Then its another challenge for us to know which message to send. Luckily MPC is great in that aspect: Just go to Options > Keys > ID column. to see the message to send.
Johnny McQuack
Posts: 5
Joined: 12 Feb 2017, 05:38

Re: Changing MPC from Playing to Paused

26 Jun 2017, 12:36

jeeswg wrote:- 'change the state from Playing to Paused' [set state]
- 'pause it if it's playing' / 'in case it's not playing' [get state]
I've tried to answer both those questions.
Ah, I see! I really don't understand anything about coding, so most of the things said in here are quite confusing to me, but thanks for explaining!
Nextron wrote:SendMessage sends a message to a process. It depends on the process whether it is designed to understand/listen to such message. Then its another challenge for us to know which message to send. Luckily MPC is great in that aspect: Just go to Options > Keys > ID column. to see the message to send.

I see, thanks for the explanation!

And thank you both again, the script is functional!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, Rohwedder, william_ahk and 48 guests