Automating window restore with AutoHotKey

Get answers about using the current release of MediaMonkey for Windows.

Moderator: Gurus

colin_e
Posts: 71
Joined: Thu Dec 28, 2006 6:39 pm

Automating window restore with AutoHotKey

Post by colin_e » Mon Jun 04, 2012 3:39 pm

OS: Windows 7 Pro 64bit
MM: 4.0.3.1470
AutoHotKey: 1.0.48.05

I've been a MediaMonkey user for years, but after buying a new keyboard with fewer multimedia control keys I thought i'd have a go at trying to control MM with what seems to be the most popular keyboard macro tool on Windows: AutoHotkey.

I was trying to do something simple, create a hotkey that-
  • If MediaMonkey isn't running, starts MediaMonkey
  • If MediaMonkey IS running, activates the window and gives it focus (opening the window if it's minimised)
Unfortunately it seems MediaMonkey is a special case, it's a real toad to try and automate.

I think MediaMonkey this is because instead of a normal Window's 3 states (Minimised to the Taskbar, Normal, or Maximised) MM has multiple "open" forms (normal view, Miniplayer, Microplayer, Invisible except in the System Tray)

Nett result is that unlike other normal Windows applications, MM ignores the AHK "WinRestore" command and the workarounds given in the AHK documentation for "badly behaved" applications. More bizarely, if you use the "WinShow" AHK command MM actually gets stuck in normal view and the windows Minimise button (the "-" symbol) no longer minimises the window, you have to cycle through one of the other views like Miniplayer before the window controls work properly again.

I tried setting up a MediaMonkey hot key and triggering that from AHK, but MM doesn't actually have a Hotkey action for "Restore". There are hotkey actions for toggling in/out of the various views like Miniplayer, but the trouble is they are just that- toggles, you have to know whether MM is currently (say) shrunk to the Systray to know whether the toggle is going to open it or close it.

I found one thread on this subject here-

http://www.mediamonkey.com/forum/viewto ... ey#p269316

but this doesn't seem to work with the latest version of MediaMonkey. I have to say this is a case where maybe MM is a bit too clever for its own good.

Any ideas or pointers would be much appreciated.

Regards: colin_e
Regards: Colin

hhcc2

Re: Automating window restore with AutoHotKey

Post by hhcc2 » Wed Jul 18, 2012 4:52 am

This is what I currently use. It is not perfect, but … Anyway, set Ctrl+Shit+m as shortcut for "Window: Minimize to tray/Maximize" within MM.

Code: Select all

W_MediaMonkeyExe = "C:\Program Files (x86)\MediaMonkey\MediaMonkey.exe"
W_MediaMonkeyClass = MediaMonkey ahk_class TFMainWindow

^!f::
DetectHiddenWindows, On
IfWinExist, %W_MediaMonkeyClass%
{
    ; requires +^m to be set for WinMinimize/Restore within media monkey
    DetectHiddenWindows, Off
    WinGet, m_IsRestorable, Count, %W_MediaMonkeyClass%
    IfEqual, m_IsRestorable, 0
    {
        DetectHiddenWindows, On
        ControlSend, , +^m, %W_MediaMonkeyClass%
        DetectHiddenWindows, Off
        WinWait, %W_MediaMonkeyClass%, , 1
        WinGet, m_IsRestorable, Count, %W_MediaMonkeyClass%
        IfEqual, m_IsRestorable, 0
        {
            DetectHiddenWindows, On
            ControlSend, , +^m, %W_MediaMonkeyClass%
        }
    }
    Else
        WinActivate, %W_MediaMonkeyClass%
    Return
}
Else
{
    TrayTip, Wait:, Launching MediaMonkey
    Run, %W_MediaMonkeyExe% /NoSplash /Play
    WinWait, %W_MediaMonkeyClass%, , 5
    WinActivate, %W_MediaMonkeyClass%
    TrayTip
}
Return

Post Reply