[Automatic Hotkey] Auto-run an existing hotkey when an app starts?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
fakerwilliam
Posts: 2
Joined: 01 May 2019, 21:48

[Automatic Hotkey] Auto-run an existing hotkey when an app starts?

01 May 2019, 22:17

- I have an app called (sizer 4.0) which uses hotkeys to resize/move selected windows.
- In sizer 4.0, one hotkey I have set is (alt + m) which resizes a window and centers it on-screen.

A few of my applications won't start up at the center of my screen (when I launch their exe files). Can someone think up a script which will automatically run a (alt + m) keystroke when I start up those applications?

For example: I double-click firefox, autohotkey sees that firefox.exe has launched, the (alt + m) keystroke will automatically register w/out me typing it?

So, quite literally, an automatic hotkey (automatically run/register a keystroke when a specific exe launches)
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: [Automatic Hotkey] Auto-run an existing hotkey when an app starts?

02 May 2019, 00:25

Try this:

Code: Select all

#SingleInstance Force
SetTitleMatchMode, RegEx

ProcessArray := []
Loop
{
    WinWaitActive, ahk_exe i)\\notepad|winword|wordpad\.exe$ 	; Wait for one of the applications to open
    WinGet, ProcessID, PID										; Get the process ID (PID) of the application's window
    If(!ProcessArray[ProcessID])								; If the window isn't recognized in the array
    {
        Send, ^m
        ProcessArray[ProcessID] := true							; Add the window's PID to the array
    }
    WinWaitNotActive											; Wait until the window is no longer active
    For index, value in ProcessArray							; Loop through the array
      If(!WinExist("ahk_pid " index))							; If any recognized window no longer exists
          ProcessArray.Delete(index)							; Delete the window's PID from the array
}
Replace the executable names on the WinWaitActive line to the names of your executables (without the ".exe"). Add more by adding more pipe (|) characters. All of the array, process and ID business is just to prevent Ctrl+M from being sent to each window more than once (at launch).
fakerwilliam
Posts: 2
Joined: 01 May 2019, 21:48

Re: [Automatic Hotkey] Auto-run an existing hotkey when an app starts?

02 May 2019, 20:35

Thanks for the response! They keystroke was (alt + m) so I switched '^m' to '!m'. That kind of works but some of the applications are .Ink files...
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: [Automatic Hotkey] Auto-run an existing hotkey when an app starts?

02 May 2019, 23:00

fakerwilliam wrote:
02 May 2019, 20:35
Thanks for the response! They keystroke was (alt + m) so I switched '^m' to '!m'. That kind of works but some of the applications are .Ink files...
Sorry about that. I misremembered you as wanting Ctrl+M.

As for .lnk files, those are just shortcuts to other files. You need to right-click on them, choose Properties and then see what the names of the files are in the Target boxes.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: arrondark, Spawnova and 223 guests