ImageSearch returning wrong coords?

Ask gaming related questions (AHK v1.1 and older)
noveske
Posts: 1
Joined: 10 Dec 2017, 19:42

ImageSearch returning wrong coords?

10 Dec 2017, 20:40

Hi,

I am having some issues returning the correct coords when using ImageSearch in a game.
The game is running in Window mode, and I have reduced down the resolution from my native resolution (i.e. My desktop is running at 3840x2160, and the game is running in window mode at 1920x1080).
(I have tried running the game in full screen window mode also without success).

ImageSearch is finding the image, but when I use the returned coords with MouseMove, its moves to the wrong location.
I assumed it was due to the CoordMode, but having tried various combinations I have ran out of ideas.

Any ideas would be greatly appreciated, Thanks

Code: Select all

#NoEnv
SetWorkingDir, %A_ScriptDir%

CoordMode, Mouse, Relative
CoordMode, Pixel, Relative
CoordMode, Tooltip, Relative

; Vars
win=mygame
img=band3.png

; Debug
Gui, add, picture, x10 y10, %img%
Gui, show, x100 y10 h70 w250, Hit F2 to Find
return

guiclose:
exitapp

f2::
WinActivate %win%
WinWaitActive, %win%
Sleep, 200

ImageSearch, X, Y, 0, 0, %a_screenwidth%, %a_screenheight%, *50 %img%
if errorlevel=1
{
	return
}
else if errorlevel=2
{
	MsgBox, Not Found
	return
}

MouseMove, X, Y
ToolTip, Found: %X% %Y%
Sleep, 4000
tooltip
return
Kim Latrashgian

Re: ImageSearch returning wrong coords?

10 Dec 2017, 20:56

is it always off by the same amount? if it is you can just adjust the X Y
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: ImageSearch returning wrong coords?

11 Dec 2017, 00:47

- Try MouseGetPos, and then MouseMove to the same coordinates, and see if there is a discrepancy, and what the pattern is.
- Based on the resolutions you state, maybe you need to double or halve the X/Y values.
- I usually prefer to use Screen coordinates rather than Window coordinates, it's possible that this would make things simpler.
- Sometimes, to be on the safe side, I use CoordMode at the start of a hotkey subroutine, just underneath the hotkey label. Also, you can retrieve the value of the A_CoordModeXXX variables to see if they are what you expected.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 40 guests