I want to click closer to the middle of the image, but when i use this code it clicks in the top left of my screen. When i enclose the FoundX2 and FoundY2 in %'s it clicks off the window and makes it slightly smaller
Code:
ImageSearch, FoundX2, FoundY2, 960, 580, 1360, 650, D:\Users\Devin\Desktop\Main\etc\etc\ahk\account maker\male_gender.PNG
if ErrorLevel = 2
Msgbox can't do the search
else if ErrorLevel = 1
Msgbox image not found
else
theX = FoundX2 + 10
theY = FoundY2 + 10
Click %theX%, %theY%
Add to a found value in imagesearch Topic is solved
- donaldthejohn
- Posts: 25
- Joined: 27 Mar 2018, 20:23
Add to a found value in imagesearch
I am a noob at coding, PLEASE be patient with me
Re: Add to a found value in imagesearch
1. id recommend ditching traditional syntax, will save you headaches in the long run
2. check how your coordmodes are set up: https://autohotkey.com/docs/commands/CoordMode.htm , specifically Mouseand Pixel
if u wanna click the middle of the image divide its width and height by two, then add these offsets to the foundX/Y
2. check how your coordmodes are set up: https://autohotkey.com/docs/commands/CoordMode.htm , specifically Mouseand Pixel
if u wanna click the middle of the image divide its width and height by two, then add these offsets to the foundX/Y
- donaldthejohn
- Posts: 25
- Joined: 27 Mar 2018, 20:23
Re: Add to a found value in imagesearch
thanks for helping,
what do you mean by traditional syntax and im not very good at coding so i have no clue what it means by "affects" on the coordmode command nor how to use it
what do you mean by traditional syntax and im not very good at coding so i have no clue what it means by "affects" on the coordmode command nor how to use it
I am a noob at coding, PLEASE be patient with me
- donaldthejohn
- Posts: 25
- Joined: 27 Mar 2018, 20:23
Re: Add to a found value in imagesearch
I tried messing around with the coordmode by changing it to pixel above the imagesearch and changing it to mouse in the else which seemed to have no effect. When i just say click %FoundX2%, %FoundY2% it clicks on that spot, however it needs to be moved more towards the middle. When i run it with a message box of the coordinates, it is in the correct place as well. It appears to me that my syntax is incorrect or i need to use coordmode in a different manner
I am a noob at coding, PLEASE be patient with me
Re: Add to a found value in imagesearch Topic is solved
read the section: https://autohotkey.com/docs/Variables.htm#Intro, then follow the links 'legacy' and 'expression' to understand the differencedonaldthejohn wrote: what do you mean by traditional syntax
this should prolly help you debug
Code: Select all
CoordMode, Pixel, Screen ; absolute coordinates - (0,0) is top-left corner of the monitor
CoordMode, Mouse, Screen ; absolute coordinates - (0,0) is top-left corner of the monitor
; CoordMode, Pixel, Relative ; relative coordinates - (0,0) is top-left corner of a window
; CoordMode, Mouse, Relative ; relative coordinates - (0,0) is top-left corner of a window
imageW := 100 ; enter ur img width here
imageH := 100 ; enter ur img height here
ImageSearch, FoundX2, FoundY2, 960, 580, 1360, 650, D:\Users\Devin\Desktop\Main\etc\etc\ahk\account maker\male_gender.PNG
if ErrorLevel = 2
Msgbox can't do the search
else if ErrorLevel = 1
Msgbox image not found
else
MsgBox, % Format("image found at ({},{})", FoundX2, FoundY2)
imageCenterX := FoundX2 + (imageW / 2)
imageCenterY := FoundY2 + (imageH / 2)
MsgBox, % Format("image center at ({},{})", imageCenterX, imageCenterY)
Click %imageCenterX%, %imageCenterY%
- donaldthejohn
- Posts: 25
- Joined: 27 Mar 2018, 20:23
Re: Add to a found value in imagesearch
Okay, thanks again, and im still confused on the legacy and expression. From what im reading, does it just mean legacy is shorthand and expression is longer? Im clearly in a lack of experience as i havent seen or used these expressions before, but i can easily follow them enough to understand what is being done and what it means. And it works!!
I am a noob at coding, PLEASE be patient with me
- donaldthejohn
- Posts: 25
- Joined: 27 Mar 2018, 20:23
Re: Add to a found value in imagesearch
I also created a much simpler version for anyone who finds this code useful. The way that is shown above for my purpose at least, is only if you're trying to be super exact and or want to share with someone else. It also helped me further my knowledge of AHK.
I am a noob at coding, PLEASE be patient with me
Who is online
Users browsing this forum: Google [Bot], RussF and 297 guests