AutoHotKey: unexpected mintty behavior

743 views Asked by At

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?

1

There are 1 answers

3
quantax On

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 -