Jump to content

mouseclick random on specific coordinates?


Recommended Posts

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 by christian11
Link to comment
Share on other sites

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 Gude
How 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

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)

userbar.png

Link to comment
Share on other sites

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

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 Gude
How 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

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 points

no 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

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 Gude
How 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

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 this

do 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 wanted

maybe there's another function? sorry im really newbie to this i hope you help me

 

 

Edited by christian11
Link to comment
Share on other sites

  • Moderators

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
EndFunc

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

so it will be

like 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()

    Exit

im confuse XD

Link to comment
Share on other sites

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   ;==>_Exit

kylomas

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

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

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

 

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

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

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   ;==>ClickRandomly

However, 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   ;==>ClickOnce

Good Luck,

kylomas

Edited 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

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
 Share

  • Recently Browsing   0 members

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