Autohotkey:Gui 提交后 ControlClick 的奇怪行为

Auto Hot Key: Strange behavior on ControlClick after Gui Submit

我有以下脚本在后台将 ControlClick + ControlSend 发送到 window(而我正在另一个 window 中工作)。按预期工作正常。

SetTitleMatchMode 2

$F1::
sleep 1000

ControlClick, x400 y470, Notepad
ControlSend,, text, Notepad

return

问题是:当我在脚本上添加 Gui 时,一旦我关闭 Gui(使用提交或销毁),ControlClick 行为就会变得奇怪:如果我在 window A (Chrome 例如)ControlClick 不再在后台工作:它激活 window B(记事本),就像在 WinActivate 命令中一样。

这是有问题的脚本(与上一个相同,但有一个简单的 Gui):

SetTitleMatchMode 2

Gui, Add, Text,, box
Gui, Add, Button, default, OK
Gui, Show, W300 H300
return

GuiClose:
ButtonOK:
Gui, Submit
return


$F1::
sleep 1000

ControlClick, x400 y470, Notepad
ControlSend,, text, Notepad

return

我在 Windows Vista 32 位,Autohotkey v1.1.25.01

我不明白为什么 Gui Submit 会改变 ControlClick 行为。我怎样才能解决这个问题,让 ControlClick 运行 在后台就像没有 Gui Submit/Destroy?

ps: windows 都最大化了。

众所周知,ControlClick 在某些情况下不是很可靠。看看 Reliability section in the ControlClick documentation,有一些你可以尝试的东西:

To improve reliability -- especially during times when the user is physically moving the mouse during the ControlClick -- one or both of the following may help:

  1. Use SetControlDelay -1 prior to ControlClick. This avoids holding the mouse button down during the click, which in turn reduces interference from the user's physical movement of the mouse.

  2. Specify the string NA anywhere in the sixth parameter (Options) as shown below:

    SetControlDelay -1  
    ControlClick, Toolbar321, WinTitle,,,, NA
    

NA avoids marking the target window as active and avoids merging its input processing with that of the script, which may prevent physical movement of the mouse from interfering (but usually only when the target window is not active). However, this method might not work for all types of windows and controls.