Imagesearch Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
xstrikerx123
Posts: 2
Joined: 18 Aug 2017, 23:47

Imagesearch

19 Aug 2017, 00:24

Trying to search for an image then click on it randomly within the image.

I got this to work but obviously its not random.

Code: Select all

 
F9::
ImageSearch, imageX, imageY, 0, 0, 1000 , 1000, login.png

if errorlevel=1
msgbox, can't find image

if errorlevel=0
 MouseMove, imageX+50, imageY+20
 
Return
So from there i tried to add in a random x y but it just moves all over my screen and not with in the image.

Code: Select all

F9::
ImageSearch, imageX, imageY, 0, 0, 1000 , 1000, login.png

Random, randX, 0, 145,
Random, randY, 0, 35,

if errorlevel=1
msgbox, can't find image

if errorlevel=0
MouseMove, imageX+randX, imageY+randY

Return
User avatar
Gio
Posts: 1247
Joined: 30 Sep 2013, 10:54
Location: Brazil

Re: Imagesearch  Topic is solved

19 Aug 2017, 10:05

Hello xstrikerx123.

Welcome to the AutoHotkey community forums.

Random command takes only 3 parameters, so there should be no comma after the third.

Code: Select all

Random, randX, 0, 145
Random, randY, 0, 35
When you put a comma after the third parameter, which is the last of this command, you cause AutoHotkey to think the value of the third parameter includes a comma, which means it will process that value as text instead of number. And since a Text has no defined mathematical value, the command Random will run without any maximum value, which will cause it to output enormously high numbers. Using these enormous numbers in MouseMove will than causes the cursor to be sent to somewhere along the borders of the screen.

As a side note, when things don't run smoothly with your code, it is usefull to use messagebox to check the contents of the variables most critical to your code, which is what revealed the issue to me.

Code: Select all

Random, randX, 0, 145,
messagebox, %RandX%
Best wishes.
xstrikerx123
Posts: 2
Joined: 18 Aug 2017, 23:47

Re: Imagesearch

19 Aug 2017, 18:32

Ah thanks Gio. I didn't even see i had done that, I spend ages wondering why it didn't work trying different things and it was that simple :D

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, mikeyww, roysubs, teadrinker and 163 guests