christian11 Posted October 6, 2015 Share Posted October 6, 2015 (edited) hi im kinda newbie here. i cant seem understand the function random from helpfile i would really appreciate if you help me I just wanted to mousclick from two specific x,y coordinates randomly .. can you suggest me how to achieve it? its something like this-> it will choose either click A or B once->then continue the other program $coordinates1= 592, 173 $coodinates2= 309 , 631 MouseClick("left", random($coordinates1), random($coordinates2) Edited October 7, 2015 by christian11 Link to comment Share on other sites More sharing options...
BrewManNH Posted October 7, 2015 Share Posted October 7, 2015 Try it this way.Global $aCoordinates1[2] = [173, 592] Global $aCoordinates2[2] = [309, 631] MouseClick("left", Random($aCoordinates1[0], $aCoordinates1[1]), Random($aCoordinates2[0], $aCoordinates2[1]))Variables can only hold one value, you tried to assign two to each of them. Second, if you're going to use variable names, you need the dollar sign ("$") in front of the variable. Third, your $coordinates1 values were reversed, the higher number must be in the second position which is the Max parameter. Being reversed, the random function will always return 0. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
christian11 Posted October 7, 2015 Author Share Posted October 7, 2015 it doesnt seem work.. why its clicking on different coordinates? i wanted it to click exactly in specific coordinates please help Link to comment Share on other sites More sharing options...
TheSaint Posted October 7, 2015 Share Posted October 7, 2015 I'm guessing that if you want the same specifics coordinates clicked each time, that the random element is for when they are clicked. In other words, a random amount of time between clicks.Is my guess correct? Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
Malkey Posted October 7, 2015 Share Posted October 7, 2015 An example of how to randomly select one of two specific points to mouse click.Local $coordinates1[2] = [592, 173] Local $coodinates2[2] = [309, 631] Local $aClick For $1 = 1 To 10 $aClick = (Random(0, 1, 1)) ? $coordinates1 : $coodinates2 MouseClick("left", $aClick[0], $aClick[1]) ConsoleWrite($aClick[0] & " " & $aClick[1] & @LF) Sleep(1000) Next. Link to comment Share on other sites More sharing options...
BrewManNH Posted October 7, 2015 Share Posted October 7, 2015 I'm not sure what you're asking christian11. What are the exact coordinates you need to click, and are you looking for a random time between those clicks? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
christian11 Posted October 7, 2015 Author Share Posted October 7, 2015 I'm guessing that if you want the same specifics coordinates clicked each time, that the random element is for when they are clicked. In other words, a random amount of time between clicks.Is my guess correct?yes i want it to click it randomly between two pointsno not random time..its something like this-> it will choose either click A or B once->then continue the other program $coordinates1= 592, 173 $coodinates2= 309 , 631 ;select coord1 or coord2 MouseClick("left", random(coordinates1), random(coordinates2) else send {f5} yada yada yada Link to comment Share on other sites More sharing options...
BrewManNH Posted October 7, 2015 Share Posted October 7, 2015 Unfortunately, you're still as clear as mud.You say you want to click between two random points, which 2 random points? You have 4 points set in your coordinate variables, and your snippet is written wrong so reposting it is not making anything clearer.What doesn't the snippet I posted NOT do that you want it to do? It takes a random number between 173 and 592 as the X position to click, and then it takes a random number between 309 and 631 as the Y position to click. What are the 2 numbers you have in each of your coordinates variables for if they're not the random position to click? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
christian11 Posted October 7, 2015 Author Share Posted October 7, 2015 (edited) because from another macro program im using.. i used to think that it will select variable from according to what I defined.its like something thisdo say @random ("hello world","whats up","hi fellas") see? it will say from what exact words i setup I think the function random is not really doing what i really wantedmaybe there's another function? sorry im really newbie to this i hope you help me Edited October 7, 2015 by christian11 Link to comment Share on other sites More sharing options...
yessiree Posted October 7, 2015 Share Posted October 7, 2015 Local $coord1[2] = [592, 173] Local $coord2[2] = [309, 631] If Random(0, 1, 1) == 1 Then ConsoleWrite("clicked 1") MouseClick("left", $coord1[0], $coord1[1]) Else ConsoleWrite("clicked 2") MouseClick("left", $coord2[0], $coord2[1]) EndIf Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 7, 2015 Moderators Share Posted October 7, 2015 christian11,Based on your pseudo-code above, this is the AutoIt equivalent:#include <MsgBoxConstants.au3> HotKeySet("{ESC}", "_Exit") Global $aArray[] = ["hello world", "whats up", "hi fellas"] While 1 ; Get a random index 0 to 2 $iRandom = Random(0, 2, 1) ; Display the random array element MsgBox($MB_SYSTEMMODAL, "Say " * $iRandom, $aArray[$iRandom]) WEnd Func _Exit() Exit EndFuncM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
christian11 Posted October 7, 2015 Author Share Posted October 7, 2015 so it will belike this??#include <MsgBoxConstants.au3> HotKeySet("{ESC}", "_Exit") Global $aArray[] = ["592, 173", "309, 631"] While 1 ; Get a random index 0 to 2 $iRandom = Random(0, 2, 1) ; Display the random array element MouseClick("left", * $iRandom, $aArray[$iRandom] ) WEnd Func _Exit() Exitim confuse XD Link to comment Share on other sites More sharing options...
kylomas Posted October 7, 2015 Share Posted October 7, 2015 christian11,See if this makes any sense...#include <StringConstants.au3> #include <MsgBoxConstants.au3> HotKeySet("{ESC}", "_Exit") Global $aArray[] = ['592,173', '309,631'] _clk_random() ; click coord 1 or 2 randomly once While 1 Sleep(99999) ; ; go do whatever else you want to do ; WEnd Func _clk_random() Local $iRnd = Random(0, 1, 1) ; get random offset, either 0 or 1 $aCoord = StringSplit($aArray[$iRnd], ',', $STR_NOCOUNT) ; split x/y coords MouseClick("left", $aCoord[0], $aCoord[1]) MsgBox($MB_SYSTEMMODAL,"","Just clicked at " & $aCoord[0] & ',' & $aCoord[1]) EndFunc ;==>_clk_random Func _Exit() Exit EndFunc ;==>_Exitkylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
computergroove Posted October 7, 2015 Share Posted October 7, 2015 (edited) I've done this and I think Christian11 may be too new to jump into arrays. This is a bit easier to understand:#include <MsgBoxConstants.au3> HotKeySet("{ESC}","_Exit") While 1 ;Choose a new random x and y coord everytime the loop restarts Local $RandomX = Random(309,592,1);Choose a whole number between 309 and 592 Local $RandomY = Random(173,631,1);Choose a whole number between 173 and 631 ;MouseClick("Left",$RandomX,$RandomY);uncomment to click random cooordinates MsgBox(0,"Random Results","X: " & $RandomX & " Y: " & $RandomY);shows a messagebox everytime a new set of coords is choosen WEnd Func _Exit() Exit 0 EndFunc Edited October 7, 2015 by computergroove Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
computergroove Posted October 7, 2015 Share Posted October 7, 2015 I may be reading this incorrectly. You want to click either (592,173) or (309,631)ClickRandomly();Call the ClickRandomly Function from within another part of the script Func ClickRandomly() Local $RandomNumber = Random(1,2,1);Randomly generate 1 or 2 If $RandomNumber == 1 Then MouseClick("Left",592,173) EndIF If $RandomNumber == 2 Then MouseClick("Left",309,631) EndIF EndFunc christian11 1 Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
kylomas Posted October 7, 2015 Share Posted October 7, 2015 @computergroove,It may be easier to understand but it does not do what I think the user wants. My understanding:randomly click one of two sets of mouse coordinates oncekylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
computergroove Posted October 7, 2015 Share Posted October 7, 2015 I added another post above your comment that fixes this. Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
kylomas Posted October 7, 2015 Share Posted October 7, 2015 Yes, I see that, thanks Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
christian11 Posted October 8, 2015 Author Share Posted October 8, 2015 I may be reading this incorrectly. You want to click either (592,173) or (309,631)ClickRandomly();Call the ClickRandomly Function from within another part of the script Func ClickRandomly() Local $RandomNumber = Random(1,2,1);Randomly generate 1 or 2 If $RandomNumber == 1 Then MouseClick("Left",592,173) EndIF If $RandomNumber == 2 Then MouseClick("Left",309,631) EndIF EndFunc thank you much it works! Link to comment Share on other sites More sharing options...
kylomas Posted October 8, 2015 Share Posted October 8, 2015 (edited) christian11,Just FYI for further consideration. If you are only dealing with two sets of coordinates then the following works fine (a simplified version of computergrooves code)ClickRandomly();Call the ClickRandomly Function from within another part of the script Func ClickRandomly() If Random(0, 1, 1) Then MouseClick("Left", 592, 173) Else MouseClick("Left", 309, 631) EndIf EndFunc ;==>ClickRandomlyHowever, if you want to expand the number of coordinates then you need something more flexible, like this...Local $aCoords = [ _ [592, 173], _ [533, 170], _ [492, 073], _ [309, 631] _ ] ClickOnce() Func ClickOnce() Local $idx = Random(0, UBound($aCoords) - 1, 1) MouseClick("left", $aCoords[$idx][0], $aCoords[$idx][1]) EndFunc ;==>ClickOnceGood Luck,kylomas Edited October 8, 2015 by kylomas Try to fix spacing Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill 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