ControlSend fails with null control for Notepad in v2 Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

ControlSend fails with null control for Notepad in v2

Post by mikeyww » 29 Jan 2023, 11:11

Works:

Code: Select all

#Requires AutoHotkey v1.1.33
F3::ControlSend,, q, ahk_exe notepad.exe
No effect:

Code: Select all

#Requires AutoHotkey v2.0
F3::ControlSend 'q',, 'ahk_exe notepad.exe'
Why :?:

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

Re: ControlSend fails with null control for Notepad in v2  Topic is solved

Post by boiler » 29 Jan 2023, 11:40

It appears that v2 is defined to act differently when the Control parameter is blank:
v1 ControlSend documentation wrote: If this parameter is blank or omitted, the target window's topmost control will be used
v2 ControlSend documentation wrote: If this parameter is omitted, the keystrokes will be sent directly to the target window instead of one of its controls

User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: ControlSend fails with null control for Notepad in v2

Post by mikeyww » 29 Jan 2023, 11:49

OK. Thanks, boiler.

Solution is below for anyone who wants it.

Code: Select all

#Requires AutoHotkey v2.0
F3::ControlSend 'q', WinGetControls(winTitle := 'ahk_exe notepad.exe')[1], winTitle

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

Re: ControlSend fails with null control for Notepad in v2

Post by boiler » 29 Jan 2023, 11:55

Nice solution.

Post Reply

Return to “Ask for Help (v2)”