1
votes

I have the following script that sends ControlClick + ControlSend to a window in background (while I'm working in another window). It works ok as expected.

SetTitleMatchMode 2

$F1::
sleep 1000

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

return

The problem is: when I add a Gui on the script, the ControlClick behavior becomes odd once I close the Gui (with Submit or Destroy): If I'm working in a window A (Chrome for example) the ControlClick don't work in background anymore: it activates the window B (Notepad) like in the WinActivate command instead.

Here's the script with the issue (same as the previous one but with a simple 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

I'm on Windows Vista 32 bits, Autohotkey v1.1.25.01

I can't understand why the Gui Submit is changing the ControlClick bahavior. How can I fix this and let the ControlClick run in background just like it was without the Gui Submit/Destroy?

ps: both windows were maximized.

1
That's really odd. Are there any other scripts running in the background? Also, take a look at the reliablility section in the ControlClick documentation, there are some things you can try: autohotkey.com/docs/commands/ControlClick.htm#Reliability Do you have access to a computer with a different version of windows on which you could try your script?Forivin
Hey @Forivin "Specify the string NA anywhere in the sixth parameter" did the trick for me, thank you very much! If you post it as an aswer would be a pleasure for me to mark it as the right answer.Le____

1 Answers

1
votes

ControlClick is known to not be very reliable in certain cases. Take a look at the Reliability section in the ControlClick documentation, there are some things you can try:

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.