Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

ControlClick strange behavior. Suggestions?


  • Please log in to reply
2 replies to this topic
hddietrich
  • Members
  • 6 posts
  • Last active: Sep 05 2016 11:47 AM
  • Joined: 19 Feb 2013

Hi guys,
 
I am working on a simple script to deal with eventual error messages from my other scripts: it scans for an error window, fixes the most common cause, and clicks YES to continue running the script. 
 
The problem is that, even with the reliability suggestions of SetControlDelay and NA, the control click often does not work on the first time. What happens is that I can literally SEE it "try" to click yes, but nothing happens. I see the window become more active, or sometimes I see the YES button becoming more "highlighted", if you know what I mean.
 
The issue is not that problematic in this instance, because I don't really care about it taking another second to resume the other scripts. My problem is that sometimes the other more important scripts, exhibit the same behavior, where a click doesn't really go through. And given their functions, a missed click is completely unacceptable.
 
So I figured to ask for help on this specific, replicable issue of closing an error prompt. It always takes exactly two tries at clicking to erradicate the error pop-up window. I am just a beginner at this, so I really hope more experienced programmers can spot the problem in a glimpse!
 
Here is my script:
 

Standby:

WinWait,, Continue running the script

Sleep 1200

WinActivate Microsoft Excel

Sleep 100

Send {Esc}

Sleep 100

SetControlDelay -1
ControlClick, Button1, , Continue running the script,,,NA

Sleep 100

Goto Standby

As I said, it's pretty simple. I hope I'm not messing anything up.
 
This is an example of the results I get when I run it: the script clearly runs twice to click Yes in one message box. After "trying" to click for the first time, it runs again, having the WinWait find the window immediately (since it was already there).

---- C:\Users\Henrique\Desktop\Bovespa Data\Scripting\0.Excel Support.ahk
003: SendMode,Input
004: SetWorkingDir,%A_ScriptDir%
010: WinWait,,Continue running the script (6.21)
012: Sleep,1200 (1.20)
014: WinActivate,Microsoft Excel (0.13)
016: Sleep,100 (0.11)
018: Send,{Esc}
020: Sleep,100 (0.11)
022: SetControlDelay,-1
023: ControlClick,Button1,,Continue running the script,,,NA
025: Sleep,100 (0.11)
027: Goto,Standby
010: WinWait,,Continue running the script (0.11)
012: Sleep,1200 (1.20)
014: WinActivate,Microsoft Excel (0.11)
016: Sleep,100 (0.11)
018: Send,{Esc}
020: Sleep,100 (0.11)
022: SetControlDelay,-1
023: ControlClick,Button1,,Continue running the script,,,NA
025: Sleep,100 (0.11)
027: Goto,Standby
010: WinWait,,Continue running the script (7.19)

Press [F5] to refresh.

Thanks in advance!



Masonjar13
  • Members
  • 1517 posts
  • Last active:
  • Joined: 16 Sep 2012

I'd suggest trying ControlFocus.

ControlFocus,Button1,,Continue running the script
ControlClick,Button1,,Continue running the script,,,NA

OS: Windows 7 Ultimate / Windows 8.1 Pro | Editor: Notepad++


hddietrich
  • Members
  • 6 posts
  • Last active: Sep 05 2016 11:47 AM
  • Joined: 19 Feb 2013

Thanks Masonjar, it worked!