Jump to content

Recommended Posts

Posted (edited)

Good day,

I have been unable to obtain an answer to my query regarding the MouseClick() function.

Two examples may be beneficial here:

#cs
The following example WILL produce an error wherein
the inital command IS NEVER completed successfully!
#ce
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
Global $iTimeOut = 100
; -----------------------------------------------
Example1()
; -----------------------------------------------
Func Example1()
    MouseClick($MOUSE_CLICK_LEFT, 684, 112, 1, 0)
    Sleep($iTimeOut)
    Send("{ALTDOWN}")
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 486, 112, 1, 0)
    Sleep($iTimeOut)
    Send("{ALTUP}")
    Sleep($iTimeOut)
    Send("I")
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 50, 160, 1, 1)
EndFunc   ;==>Example1
; -----------------------------------------------

============================================

#cs
The following example will NOT produce an error wherein
the inital command IS completed successfully!
#ce
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
Global $iTimeOut = 100
; -----------------------------------------------
Example2()
; -----------------------------------------------
Func Example2()
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 684, 112, 1, 0)
    Sleep($iTimeOut)
    Send("{ALTDOWN}")
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 486, 112, 1, 0)
    Sleep($iTimeOut)
    Send("{ALTUP}")
    Sleep($iTimeOut)
    Send("I")
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 50, 160, 1, 1)
EndFunc   ;==>Example2
; -----------------------------------------------

My question is, "Is a pause generally required prior to the execution of a MouseClick() function?"

What is even "odder" to me is that I often have to execute scripts more-than-once in order to obtain the results that are required!?! "Why?"

As always...any assistance in this matter would be greatly appreciated!

Thank you all for your time!

Edited by mr-es335
Posted

Nine,

You stated, "If you're running this script in a loop, then you are not leaving enough time to the last click to complete."

I do NOT believe that I am running this script in a loop - just within a single function call. If I am not running this script in a loop, would the following be appropriate?...

; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
Global $iTimeOut = 100
; -----------------------------------------------
Example3a()
; -----------------------------------------------
Func Example3a()
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 684, 112, 1, 0)
    Sleep($iTimeOut)
    Send("{ALTDOWN}")
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 486, 112, 1, 0)
    Sleep($iTimeOut)
    Send("{ALTUP}")
    Sleep($iTimeOut)
    Send("I")
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 50, 160, 1, 1)
EndFunc   ;==>Example3a
; -----------------------------------------------

...or...

; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
Global $iTimeOut = 100
; -----------------------------------------------
Example3b()
; -----------------------------------------------
Func Example3b()
    Sleep($iTimeOut) ; <<<=== Here!...
    MouseClick($MOUSE_CLICK_LEFT, 684, 112, 1, 0)
    Sleep($iTimeOut)
    Send("{ALTDOWN}")
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 486, 112, 1, 0)
    Sleep($iTimeOut)
    Send("{ALTUP}")
    Sleep($iTimeOut)
    Send("I")
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 50, 160, 1, 1)
    Sleep($iTimeOut)    ; <<<=== and Here!...
EndFunc   ;==>Example3b
; -----------------------------------------------

Finally, what of this?...

; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
Global $iTimeOut = 100
; -----------------------------------------------
Example4()
; -----------------------------------------------
Func Example4()
    Local $hSAC_SCENES = "[CLASS:SAC_SCENES]"
    ; -----------------------------------------------
    WinActivate($hSAC_SCENES)
    ; -----------------------------------------------
    Send("{End}")    ; Select: [End Of List]
    ; -----------------------------------------------
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 188, 118, 1, 0)    ; Select: [New]
    ; -----------------------------------------------
    Sleep($iTimeOut)
    ClipPut("====Fades====")    ; Copy text
    ; -----------------
    Send("{CTRLDOWN}")
    Send("v")    ; Paste text
    Send("{CTRLUP}")
    ; ----------------------
    Send("{ENTER}")    ; Select: [Ok]
EndFunc   ;==>Example4
; -----------------------------------------------

Any assistance here would be greatly appreciated!

Posted

1- you can put sleep anywhere / everywhere.  It doesn't hurt except can slow down the script.  You need to test and decide.

2- having a single delay ($iTimeOut) is a very bad idea.  Sometimes, it requires more time, sometimes it requires less.  You need to test and decide.

3- it is not because you paste something that it will be pasted instantly in the field.  It may take some time.  You need to test and decide.

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...