How to trap AutoHotkey to the window I want

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
roysubs
Posts: 428
Joined: 29 Sep 2018, 16:37

How to trap AutoHotkey to the window I want

31 Mar 2024, 04:44

I see that a Chocolatey package for GhostScript is using the following AutoHotkey to automate their installation.

This seems to trap AutoHotkey so that it only sends keypresses into the correct Window.

What part of this code is controlling that please? Is it the "ControlSend"? I've never really figured out how to trap AutoHotkey into exactly the right place I want it to send keypresses.

Code: Select all

#Requires AutoHotkey v2.0
#NoTrayIcon
#SingleInstance Force
#Warn
SetTitleMatchMode "RegEx"
exe_re := "gs.+.exe"

If WinWait("ahk_exe " exe_re, "Next >", 20)
   ControlSend "{ENTER}",, "ahk_exe " exe_re
Else
   exit 1

If WinWait("ahk_exe " exe_re, "I Agree", 20)
   ControlSend "{ENTER}",, "ahk_exe " exe_re
Else
   exit 1

If WinWait("ahk_exe " exe_re, "Install", 20)
   ControlSend "{ENTER}",, "ahk_exe " exe_re
Else
   exit 1

If WinWait("ahk_exe " exe_re, "Finish", 20)
   ControlSend "{ENTER}",, "ahk_exe " exe_re
Else
   exit 1

if WinWait("ahk_exe " exe_re, "OK", 20)
   ControlSend "{ENTER}",, "ahk_exe " exe_re
Else
   exit 1

ExitApp
User avatar
boiler
Posts: 17278
Joined: 21 Dec 2014, 02:44

Re: How to trap AutoHotkey to the window I want

31 Mar 2024, 06:24

Yes, ControlSend sends keystrokes to a particular window. The very first line on its documentation page clearly states that.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Chunjee, felipe93 and 124 guests