Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

random mouse click within specific range



  • Please log in to reply
4 replies to this topic
slanderman
  • Members
  • 4 posts
  • Last active: May 03 2013 10:57 PM
  • Joined: 03 May 2013

working on a script for a game that i've been toying with.  The script works well function wise, but now I want to "de-humanize" it.  make the mouse clicks to be random within a range and going to add the ellipse function eventually.  I've seen some random click functions that are built with 2 ranges, x, y, but what I'm looking for is one that works with 4 coordinates and I'm not sure how to do it, ie (x, y) + (x, y), 1 point for each corner of a button.

MouseClick, , % Random(150,250), % Random(150,250)

Random(min,max) {
	Random, out, %min%, %max%
	return	out
}

Something like this I think?  When I use this, the portion that I call is this right? :MouseClick, , % Random(150,250), % Random(150,250)

and just change the numbers to my own coordinates?

 

Inside the function portion, do I need the 'return out' ?  what does it do?



MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009

What have you tried so far? Running/modifying the script?

This topic points to many relevant documentation pages, in case you haven't read yet: http://www.autohotke...al-for-newbies/


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


slanderman
  • Members
  • 4 posts
  • Last active: May 03 2013 10:57 PM
  • Joined: 03 May 2013

I set it up with paint.  drew a square in paint, took coordinates of the top left corner and bottom right corner and plugged them into the script and ran it in a Loop 120.  I dont know why its only clicking in this one area, it should be spread throughout the entire square. 

RandomSleep(min, max) {

    Random, rand, min, max

    Sleep rand

}

Random(min,max) {
	Random, out, %min%, %max%
	return	out
}

IfWinExist, Untitled - Paint
    WinActivate
else
    WinActivate, Nothing
Loop 120
{
MouseClick, , % Random(215,268), % Random(362,421)
;above is bottom left coordinate then top right
RandomSleep(300, 700)

}

8705420810_0e9de31c31.jpg

If I use this same script and try to make it click on a web button, its nowhere near the button when it clicks.

MouseClick, , % Random(X,Y), % Random(X,Y) <--- is this correct?



MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
✓  Best Answer

Oh, I see your mistake.

 

You thought the code was doing

MouseClick, , % Random(X,Y), % Random(X,Y)

but the real meaning of what's happening is

MouseClick, , % Random(MinX,MaxX), % Random(MinY,MaxY)

 

Another note:

Random() uses correctly    Random, out, %min%, %max%

But you should fix RandomSleep() to use    Random, rand, %min%, %max%


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


slanderman
  • Members
  • 4 posts
  • Last active: May 03 2013 10:57 PM
  • Joined: 03 May 2013

yes!  thank you for pointing that out, working great now :)