olo Posted September 16, 2013 Share Posted September 16, 2013 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)? Link to comment Share on other sites More sharing options...
JohnOne Posted September 16, 2013 Share Posted September 16, 2013 No native function, and no UDF that I've seen or heard of. Of course you could make one. There are UDF's which gather information about Windows/GUIs, so that's where you could start. olo 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Gianni Posted September 16, 2013 Share Posted September 16, 2013 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 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Malkey Posted September 16, 2013 Share Posted September 16, 2013 This example randomly clicks controls within a chosen window. This example chose the Calculator window. expandcollapse popup#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. olo 1 Link to comment Share on other sites More sharing options...
olo Posted September 16, 2013 Author Share Posted September 16, 2013 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 Link to comment Share on other sites More sharing options...
olo Posted September 16, 2013 Author Share Posted September 16, 2013 This example randomly clicks controls within a chosen window. This example chose the Calculator window. expandcollapse popup#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. Link to comment Share on other sites More sharing options...
Malkey Posted September 16, 2013 Share Posted September 16, 2013 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. olo 1 Link to comment Share on other sites More sharing options...
czardas Posted September 16, 2013 Share Posted September 16, 2013 (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. Edited September 16, 2013 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
olo Posted September 18, 2013 Author Share Posted September 18, 2013 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? Link to comment Share on other sites More sharing options...
Gianni Posted September 18, 2013 Share Posted September 18, 2013 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 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Malkey Posted September 18, 2013 Share Posted September 18, 2013 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" Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now