I've tried this:
This finds the image some days, and some days it does not. And when it's not finding the image, if I move the app in which I'm searching for the image to another screen, that sometimes works. Whether the image is being found or not, imagesearch returns the same coordinates across repeated attempts (whether those coordinates are correct or not).
Code: Select all
screenWidth = 1920 screenHeight = 1080 #F4:: ; click image CoordMode, Pixel, Relative CoordMode, Mouse, Relative ImageSearch, X, Y, 0, 0, %screenWidth%, %screenHeight%, *100, %imageToSearchFor% Sleep, 100 MouseClick, left, X, Y return
I then discovered SysGet, and I tried this:
Not only does this not find the image, the coordinates it returns are not consistent across repeated attempts. I think this has to do with the non-rectangular desktop. VirtualScreenLeft, VirtualScreenTop are not coordinates that actually exist on this desktop. I.e., VirtualScreenLeft refers to the left edge of the leftmost monitor, and VirtualScreenTop refers to the top edge of the one monitor that is above 2nd monitor from the left.
Code: Select all
#F4:: ; click image CoordMode, Pixel, Screen CoordMode, Mouse, Screen SysGet, VirtualScreenWidth, 78 SysGet, VirtualScreenHeight, 79 SysGet, VirtualScreenLeft, 76 SysGet, VirtualScreenTop, 77 ImageSearch, X, Y, VirtualScreenLeft, VirtualScreenTop, VirtualScreenLeft+VirtualScreenWidth, VirtualScreenTop+VirtualScreenHeight, *100, %imageToSearchFor% Sleep, 100 MouseClick, left, X, Y return
Any suggestions on how I can get imagesearch to return the correct coordinates?
I'm a bit confused as to why the first code doesn't always work. If CoordMode Pixel and Mouse are both set to relative, then imagesearch and mouseclick are relative to the active screen, so as long as the app in which I'm searching for the image is the active window, why does it matter if there are other screens or how many there are or where they are placed?