Jump to content

Recommended Posts

Posted

hey folks,

I have a program open and I want to test its stability before it basically breaks down and gives me closing errors etc.

Is there an autoit function which can just start click or activating random controls on the current window(program window)? :)

Posted

this simply clicks on random positions within the window of your choice, (not exactly on controls)

Local $MyWindow = "YourWindowTitle"
Local $WinClientSize = WinGetClientSize($MyWindow)
Local $Buttons[3] = ["left", "right", "middle"]
Local $z = 0
Local $k = 1
AutoItSetOption("MouseCoordMode", 2) ; relative coords to the client area of the active window
For $mad = 1 To 10 ; how many times
    If WinExists($MyWindow) Then ; is window still open?
        WinActivate($MyWindow)
        $x = Random(1, $WinClientSize[0], 1)
        $y = Random(1, $WinClientSize[1], 1)
        ; $z = Random(0, 2, 1) ; which button
        ; $k = Random(1, 3, 1) ; how many clicks
        MouseClick($Buttons[$z], $x, $y, $k, 0) ; MouseClick
    Else
        ExitLoop
    EndIf
    Sleep(5)
Next
AutoItSetOption("MouseCoordMode", Default) ; back to default

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Posted

This example randomly clicks controls within a chosen window. This example chose the Calculator window.

#include <WinAPI.au3>
#include <Array.au3>
#include <Misc.au3>
Opt("MouseCoordMode", 2) ;1=absolute, 0=relative, 2=client

Local $sWinTitle = "[Title:Calculator]", $iIndex = 1, $iRndNum

If WinExists($sWinTitle) = 0 Then Run("Calc.exe")
WinActivate("[Title:Calculator]")
WinWaitActive("[Title:Calculator]")

_RandomlyClickControls($sWinTitle)


Func _RandomlyClickControls($WindowTitle)
    Local $text = WinGetClassList($WindowTitle, "")
    $text = StringStripWS($text, 2)
    Local $aText = StringRegExp($text, "\V+", 3)
    _ArraySort($aText)
    Local $aClassNN[UBound($aText)]
    $aClassNN[0] = $aText[0] & $iIndex
    For $i = 1 To UBound($aText) - 1
        If $aText[$i] = $aText[$i - 1] Then
            $iIndex += 1
        Else
            $iIndex = 1
        EndIf
        $aClassNN[$i] = $aText[$i] & $iIndex
    Next
    Do
        $iRndNum = Random(0, UBound($aClassNN) - 1, 1)
        Local $aPos = ControlGetPos($WindowTitle, "", $aClassNN[$iRndNum])
        MouseMove($aPos[0] + 4, $aPos[1] + 4, 10)
        MouseClick("left")
        Sleep(1000)
    Until _IsPressed("1B") ; Press and hold "Esc" key for over a second to exit
EndFunc   ;==>_RandomlyClickControls

Occasionally, you may need to click on "CE" button due to "invalid input" occurring.

Posted

 

this simply clicks on random positions within the window of your choice, (not exactly on controls)

Local $MyWindow = "YourWindowTitle"
Local $WinClientSize = WinGetClientSize($MyWindow)
Local $Buttons[3] = ["left", "right", "middle"]
Local $z = 0
Local $k = 1
AutoItSetOption("MouseCoordMode", 2) ; relative coords to the client area of the active window
For $mad = 1 To 10 ; how many times
    If WinExists($MyWindow) Then ; is window still open?
        WinActivate($MyWindow)
        $x = Random(1, $WinClientSize[0], 1)
        $y = Random(1, $WinClientSize[1], 1)
        ; $z = Random(0, 2, 1) ; which button
        ; $k = Random(1, 3, 1) ; how many clicks
        MouseClick($Buttons[$z], $x, $y, $k, 0) ; MouseClick
    Else
        ExitLoop
    EndIf
    Sleep(5)
Next
AutoItSetOption("MouseCoordMode", Default) ; back to default

Thanks for that :)

Posted

This example randomly clicks controls within a chosen window. This example chose the Calculator window.

#include <WinAPI.au3>
#include <Array.au3>
#include <Misc.au3>
Opt("MouseCoordMode", 2) ;1=absolute, 0=relative, 2=client

Local $sWinTitle = "[Title:Calculator]", $iIndex = 1, $iRndNum

If WinExists($sWinTitle) = 0 Then Run("Calc.exe")
WinActivate("[Title:Calculator]")
WinWaitActive("[Title:Calculator]")

_RandomlyClickControls($sWinTitle)


Func _RandomlyClickControls($WindowTitle)
    Local $text = WinGetClassList($WindowTitle, "")
    $text = StringStripWS($text, 2)
    Local $aText = StringRegExp($text, "\V+", 3)
    _ArraySort($aText)
    Local $aClassNN[UBound($aText)]
    $aClassNN[0] = $aText[0] & $iIndex
    For $i = 1 To UBound($aText) - 1
        If $aText[$i] = $aText[$i - 1] Then
            $iIndex += 1
        Else
            $iIndex = 1
        EndIf
        $aClassNN[$i] = $aText[$i] & $iIndex
    Next
    Do
        $iRndNum = Random(0, UBound($aClassNN) - 1, 1)
        Local $aPos = ControlGetPos($WindowTitle, "", $aClassNN[$iRndNum])
        MouseMove($aPos[0] + 4, $aPos[1] + 4, 10)
        MouseClick("left")
        Sleep(1000)
    Until _IsPressed("1B") ; Press and hold "Esc" key for over a second to exit
EndFunc   ;==>_RandomlyClickControls

Occasionally, you may need to click on "CE" button due to "invalid input" occurring.

This is really helpful thanks! What is the pattern of the clicking? Or how do you achieve the randomness.

Posted

This is really helpful thanks! What is the pattern of the clicking? Or how do you achieve the randomness.

Func _RandomlyClickControls($WindowTitle)
    Local $text = WinGetClassList($WindowTitle, "")
    $text = StringStripWS($text, 2)
    Local $aText = StringRegExp($text, "\V+", 3)
    _ArraySort($aText)
    Local $aClassNN[UBound($aText)]
    $aClassNN[0] = $aText[0] & $iIndex
    For $i = 1 To UBound($aText) - 1
        If $aText[$i] = $aText[$i - 1] Then
            $iIndex += 1
        Else
            $iIndex = 1
        EndIf
        $aClassNN[$i] = $aText[$i] & $iIndex
    Next
    Do
        $iRndNum = Random(0, UBound($aClassNN) - 1, 1)
        Local $aPos = ControlGetPos($WindowTitle, "", $aClassNN[$iRndNum])
        MouseMove($aPos[0] + 4, $aPos[1] + 4, 10)
        MouseClick("left")
        Sleep(1000)
    Until _IsPressed("1B") ; Press and hold "Esc" key for over a second to exit
EndFunc   ;==>_RandomlyClickControls
$aClassNN[$iRndNum] in the ControlGetPos function, line#18, creates the random selection of a control.

All the ClassnameNN property of each control of the selected window are in the $aClassNN array, line#14. The ClassnameNN property is made up of the Class of the control and the Instance of the control. The ClassnameNN identifies each control and is used as the controlID parameter of the ControlGetPos function, line#18.

So, the random control selection is made by selecting one of the elements in the $aClassNN array. This random selection is done by using a random number in the array index. This random index number is stored in the $iRndNum variable, line#17.

Posted (edited)

LOL, funny topic. How about adding a random delay between clicks. To be honest, predicting and testing for faults using a logical framework is likely to be more effective. :D

Edited by czardas
Posted

Func _RandomlyClickControls($WindowTitle)
    Local $text = WinGetClassList($WindowTitle, "")
    $text = StringStripWS($text, 2)
    Local $aText = StringRegExp($text, "\V+", 3)
    _ArraySort($aText)
    Local $aClassNN[UBound($aText)]
    $aClassNN[0] = $aText[0] & $iIndex
    For $i = 1 To UBound($aText) - 1
        If $aText[$i] = $aText[$i - 1] Then
            $iIndex += 1
        Else
            $iIndex = 1
        EndIf
        $aClassNN[$i] = $aText[$i] & $iIndex
    Next
    Do
        $iRndNum = Random(0, UBound($aClassNN) - 1, 1)
        Local $aPos = ControlGetPos($WindowTitle, "", $aClassNN[$iRndNum])
        MouseMove($aPos[0] + 4, $aPos[1] + 4, 10)
        MouseClick("left")
        Sleep(1000)
    Until _IsPressed("1B") ; Press and hold "Esc" key for over a second to exit
EndFunc   ;==>_RandomlyClickControls
$aClassNN[$iRndNum] in the ControlGetPos function, line#18, creates the random selection of a control.

All the ClassnameNN property of each control of the selected window are in the $aClassNN array, line#14. The ClassnameNN property is made up of the Class of the control and the Instance of the control. The ClassnameNN identifies each control and is used as the controlID parameter of the ControlGetPos function, line#18.

So, the random control selection is made by selecting one of the elements in the $aClassNN array. This random selection is done by using a random number in the array index. This random index number is stored in the $iRndNum variable, line#17.

 

Is there a way to get it to stop after say 4 attempted control clicks. So effectively removing the until esc is pressed?

Posted

Is there a way to get it to stop after say 4 attempted control clicks. So effectively removing the until esc is pressed?

 

do these small additions as pointed by the arrows in the listing (lines 10, 11, 31, 33);

and then call the function in this way _RandomlyClickControls($ sWinTitle, 4) where 4 (or any other number) is the number of strikes you want to perform

Func _RandomlyClickControls($WindowTitle, $Rounds = 1)  ; <--- added $Rounds = 1 (default)
    Local $round = 0                                    ; <--- var declaration
    Local $text = WinGetClassList($WindowTitle, "")
    $text = StringStripWS($text, 2)
    Local $aText = StringRegExp($text, "\V+", 3)
    _ArraySort($aText)
    Local $aClassNN[UBound($aText)]
    $aClassNN[0] = $aText[0] & $iIndex
    For $i = 1 To UBound($aText) - 1
        If $aText[$i] = $aText[$i - 1] Then
            $iIndex += 1
        Else
            $iIndex = 1
        EndIf
        $aClassNN[$i] = $aText[$i] & $iIndex
    Next
    Do
        $iRndNum = Random(0, UBound($aClassNN) - 1, 1)
        Local $aPos = ControlGetPos($WindowTitle, "", $aClassNN[$iRndNum])
        MouseMove($aPos[0] + 4, $aPos[1] + 4, 10)
        MouseClick("left")
        $round += 1                                     ; <--- stroke counter
        Sleep(1000)
    Until $round = $Rounds or _IsPressed("1B") ; <--- Press and hold "Esc" key for over a second to exit    <--- check
EndFunc   ;==>_RandomlyClickControls

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Posted

Is there a way to get it to stop after say 4 attempted control clicks. So effectively removing the until esc is pressed?

Instead of the Do....Until _IsPressed("1B") loop, replace with a For... Next loop.

That is:-

replace "Do" with "For $i = 1 to 4" for four loops; and,

replace "Until _IsPressed("1B")" with "Next"

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...