Sunday 25 January 2015

Autohotkey image search and click not working

Those of your out there may have had issues with the ImageSearch command in Autohotkey not lining up with MouseMove coordinates FoundX and FoundY

This is an issue with Autohotkey but after some persistence (of choosing a plethora of different coordinate modes and other settings) it seems it's related to different resolution settings.

The workaround is to change the screen resolution to a lower setting and change it back again once completed. This aligns the image coordinates to the mousemove coordinates in Autohotkey.



#z::
ChangeResolution(1024,768)
settitlematchmode 2

Sleep, 2000
Run https://somesite.com

Sleep, 4000
CoordMode Pixel, Relative

ImageSearch, FoundX, FoundY, 0, 0, 1000, 1000, *50 C:\Users\uid\Documents\testfiles\c.bmp
if ErrorLevel = 2
    MsgBox Could not conduct the search.
else if ErrorLevel = 1
    MsgBox Icon could not be found on the screen.
else
MouseMove, %FoundX%, %FoundY% 
Click

MsgBox   %FoundX%, %FoundY% 
ChangeResolution(2160,1440)
Return

ChangeResolution(w,h) {
  VarSetCapacity(dM,156,0)
  NumPut(156,dM,36)
  NumPut(0x5c0000,dM,40)
  NumPut(w,dM,108)
  NumPut(h,dM,112)
  DllCall( "ChangeDisplaySettingsA", UInt,&dM, UInt,0 )

}

No comments:

Post a Comment