1

I'm using AutoHotKey to show/hide a mintty terminal window. Here's my AutoHotkey.ahk:

ShowHide_(Title, CommandLine)
{
    OutputDebug, ShowHide called

    DetectHiddenWindows, On
    ; MatchMode = 2 : The title contains the expression
    SetTitleMatchMode, 2

    OutputDebug, Looking for a window named "%Title%"
    IfWinExist %Title%
    {
        OutputDebug, "%Title%" found, is it active?
        IfWinNotActive %Title%
        {
            WinShow
            WinWait, %Title%
            WinRestore
            WinActivate
            OutputDebug, Window is not active, activating...
        }
        Else
        {
            WinMinimize
            WinHide
            OutputDebug, Window is active, hiding...
        }
    }
    Else
    {
        OutputDebug, "%Title%" doesn't exist, starting...
        Run, %CommandLine%
    }
}

#^::
F1::ShowHide_("ahk_class mintty", "C:\cygwin\bin\mintty.exe -t CygTerm")

As you notice, I made a generic function to be able to do the same with other applications. Besides I've assigned two keyboard combinations F1 and Win+^. Both combinations work fine to launch the program or show the pre-existing window, but fails to hide it, for two reasons:

  1. When using F1, the key press is not even recognized (no trace in DbgView);
  2. When using Win+^ (or other shortcut not using Fn keys), the event is traced in DbgView, but nothing happens.

With other programs (such as Notepad++, calc, ...) everything works as expected. Any idea why? and how can I make it work?

gregseth
  • 12,952
  • 15
  • 63
  • 96
  • 1
    I suspect that mintty is intercepting those keypresses when it's active. Play around with combinations of `#InstallKeybdHook` and `#UseHook` (put them at the top of your script). – MCL Aug 09 '13 at 13:40

1 Answers1

1

I find that if I'm using the Cygwin Terminal shortcut that's automatically created in the start menu, Mintty doesn't properly respond to AHK scripts.

However, if I make a shortcut directly to the mintty.exe file (C:\cygwin\bin\mintty.exe) then it will work.

Note: In order to make the custom mintty shortcut work properly, you'll need to add a hyphen "-" as a launch option. Thus, in the shorcut, the Target field should look like this:

C:\Cygwin\bin\mintty.exe -

quantax
  • 11
  • 1
  • 1
    I don't think that answers the question. As OP said, his script "works fine to launch the program or show the pre-existing window, **but fails to hide it**". Running it doesn't seem to be the problem. – MCL Aug 11 '13 at 19:05
  • I think it does, though. When launching Mintty or showing the window, it doesn't actually interact with the Mintty window -- it's telling the Windows display manager to show it, or launch it. Once it's launched, however, Mintty doesn't respond to AHK, so it won't actually hide. I would recommend trying it with my solution and see if it resolves the problem. – quantax Aug 11 '13 at 19:13
  • @quantax no, it does not. The behavior is exactly the same. – gregseth Aug 12 '13 at 07:09