detecting menus in mpc-hc

Get help with using AutoHotkey and its commands and hotkeys
glc650
Posts: 5
Joined: 12 Mar 2017, 05:43

detecting menus in mpc-hc

06 Sep 2018, 03:44

Hi,

I've been trying to adapt the code in these threads:

https://autohotkey.com/board/topic/8576 ... n-any-app/
https://autohotkey.com/board/topic/2385 ... text-menu/

to my liking but I'm not having much luck (all I get is the msg GetGUIThreadInfo() indicated a failure.).

Here's what I want to do while mpc-hc is playing:

if a menu is opened I want the down key to function as normal, otherwise I want to map the down key to another hotkey.

Thanks,

->g.
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: detecting menus in mpc-hc

06 Sep 2018, 04:26

- This is an absolutely classic AutoHotkey problem. Custom functionality for the arrow keys when menu bars aren't active and context menus aren't visible.
- Here's a function that I use, and a basic demo script.

Code: Select all


~Up::
~Down::
~Left::
~Right::
if JEE_MenuIsActive()
	SoundBeep
return

;==================================================

;e.g.
;^q::
;WinGet, hWnd, ID, A
;MsgBox, % JEE_MenuIsActive(hWnd, "m") " " JEE_MenuIsActive(hWnd, "s") " " JEE_MenuIsActive(hWnd, "c")
;return

;e.g. vMenuIsActive := JEE_IsMenuActive()

;check if menu bar/system menu/context menu active
;m: menu bar is active
;s: sysmenu is active
;c: a context menu window is visible

;JEE_WinMenuIsActive
JEE_MenuIsActive(hWnd:=0, vOpt:="msc")
{
	if !hWnd
		hWnd := WinExist("A")
	if InStr(vOpt, "m")
	{
		vSize := A_PtrSize=8?48:32
		VarSetCapacity(MENUBARINFO, vSize, 0)
		NumPut(vSize, &MENUBARINFO, 0, "Ptr")
		;OBJID_MENU := 0xFFFFFFFD ;menu bar
		DllCall("user32\GetMenuBarInfo", Ptr,hWnd, Int,0xFFFFFFFD, Int,0, Ptr,&MENUBARINFO)
		if (NumGet(&MENUBARINFO, (A_PtrSize=8?40:28), "UChar") & 2)
			return 1
	}
	if InStr(vOpt, "s")
	{
		vSize := A_PtrSize=8?48:32
		vOffset := A_PtrSize=8?40:28
		VarSetCapacity(MENUBARINFO, vSize, 0)
		NumPut(vSize, &MENUBARINFO, 0, "Ptr")
		;OBJID_SYSMENU := 0xFFFFFFFF ;defined as this in WinUser.h and not as -1
		DllCall("user32\GetMenuBarInfo", Ptr,hWnd, Int,0xFFFFFFFF, Int,0, Ptr,&MENUBARINFO)
		if (NumGet(&MENUBARINFO, vOffset, "UChar") & 2)
			return 1
	}
	if InStr(vOpt, "c")
	{
		;if WinExist("ahk_class #32768")
		;	return 1

		vDHW := A_DetectHiddenWindows
		DetectHiddenWindows, Off
		hWnd := WinExist("ahk_class #32768")
		DetectHiddenWindows, % vDHW
		if hWnd
			return 1
	}
	return 0
}

;==================================================
- PS MPC for the win.
jeeswg's Media Player Classic tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=41683
- PSS It's a good of example of why I think ahk_dhw/ahk_mode are needed!
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
glc650
Posts: 5
Joined: 12 Mar 2017, 05:43

Re: detecting menus in mpc-hc

06 Sep 2018, 16:50

Here's what I came up with:

Code: Select all

#IfWinActive, ahk_class MediaPlayerClassicW, Playing
	{
~Down::
if not JEE_MenuIsActive()
			WinGetPos, , , W, H, A
			H -= 45
			W := w/2
			SendInput, {Click %W%, %H%, 0} ; view info
			Sleep, 3000
			SendInput, {Click 360, 0, 0} ; ensure controls are hidden
			Sleep, 500
			SendInput, ^r ; reset madVR OSD
return

;==================================================

;e.g.
;^q::
;WinGet, hWnd, ID, A
;MsgBox, % JEE_MenuIsActive(hWnd, "m") " " JEE_MenuIsActive(hWnd, "s") " " JEE_MenuIsActive(hWnd, "c")
;return

;e.g. vMenuIsActive := JEE_IsMenuActive()

;check if menu bar/system menu/context menu active
;m: menu bar is active
;s: sysmenu is active
;c: a context menu window is visible

;JEE_WinMenuIsActive
JEE_MenuIsActive(hWnd:=0, vOpt:="msc")
{
	if !hWnd
		hWnd := WinExist("A")
	if InStr(vOpt, "m")
	{
		vSize := A_PtrSize=8?48:32
		VarSetCapacity(MENUBARINFO, vSize, 0)
		NumPut(vSize, &MENUBARINFO, 0, "Ptr")
		;OBJID_MENU := 0xFFFFFFFD ;menu bar
		DllCall("user32\GetMenuBarInfo", Ptr,hWnd, Int,0xFFFFFFFD, Int,0, Ptr,&MENUBARINFO)
		if (NumGet(&MENUBARINFO, (A_PtrSize=8?40:28), "UChar") & 2)
			return 1
	}
	if InStr(vOpt, "s")
	{
		vSize := A_PtrSize=8?48:32
		vOffset := A_PtrSize=8?40:28
		VarSetCapacity(MENUBARINFO, vSize, 0)
		NumPut(vSize, &MENUBARINFO, 0, "Ptr")
		;OBJID_SYSMENU := 0xFFFFFFFF ;defined as this in WinUser.h and not as -1
		DllCall("user32\GetMenuBarInfo", Ptr,hWnd, Int,0xFFFFFFFF, Int,0, Ptr,&MENUBARINFO)
		if (NumGet(&MENUBARINFO, vOffset, "UChar") & 2)
			return 1
	}
	if InStr(vOpt, "c")
	{
		;if WinExist("ahk_class #32768")
		;	return 1

		vDHW := A_DetectHiddenWindows
		DetectHiddenWindows, Off
		hWnd := WinExist("ahk_class #32768")
		DetectHiddenWindows, % vDHW
		if hWnd
			return 1
	}
	return 0
}

;==================================================

	}
Problem is it sitll doesn't quite work right. Down arrow with no menu causes the volume to drop (default down key mapping in mpc-hc) before executing the rest. And when there is a menu, down key works but also executes everything under if not JEE_MenuIsActive(). If I remove the "~" before Down:: then the non-menu function works perfectly but when there is a menu its completely broken.
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: detecting menus in mpc-hc

06 Sep 2018, 18:27

- This will probably work. But I'm not sure what you're trying to do, there might be an easier way.
- [EDIT:] I suppose you're trying to hover over something to show some information in a ToolTip.

Code: Select all

$Down::
if not JEE_MenuIsActive()
{
			WinGetPos, , , W, H, A
			H -= 45
			W := w/2
			SendInput, {Click %W%, %H%, 0} ; view info
			Sleep, 3000
			SendInput, {Click 360, 0, 0} ; ensure controls are hidden
			Sleep, 500
			SendInput, ^r ; reset madVR OSD
}
else
	SendInput, {Down}
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
glc650
Posts: 5
Joined: 12 Mar 2017, 05:43

Re: detecting menus in mpc-hc

06 Sep 2018, 19:34

looks like that will work just need to test it with my main script now. I'm using autohotkey in conjunction with a harmony hub remote. The down button on the remote is mapped to down key on kb. When down is pressed without a menu open it moves the mouse around to bring up the mpc-hc info bar so I can see how much time is left; then hides it again. When a menu is open I wanted the down key to work as expected so I can navigate said menu from the remote and not have to grab my air mouse.

Thanks for the help,

->g.
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: detecting menus in mpc-hc

06 Sep 2018, 19:46

Here are some alternatives for displaying the time.

Code: Select all

q:: ;media player classic - display time
ControlGetText, vText, Static2, A

Progress, zh0 b1 c0 fs18, % vText
Sleep, 1000
Progress, Off

ToolTip, % vText
Sleep, 1000
ToolTip

MsgBox, % vText
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], BushMange, CEA6597, Google [Bot], VACO BenQ, w0z and 189 guests