I need help detecting an image on screen

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mexican scientist
Posts: 33
Joined: 02 Jul 2020, 21:55

I need help detecting an image on screen

12 Jan 2023, 00:15

Before I come to the forums, I do a little bit or research first. I want to make a code that detects an image in a video game called Elder Scrolls Online. So, I came across an old post that explained how to do this and the code they provided was this:

Code: Select all

IF NOT A_IsAdmin
{
   Run *RunAs "%A_ScriptFullPath%"
   ExitApp
}
SetWorkingDir, %A_ScriptDir%

CoordMode, Mouse, Client
CoordMode, Pixel, Client
CoordMode, ToolTip, Client
SetKeyDelay,50,50



Z::
ImageSearch, FoundX, FoundY, 814,999, 1102, 1061, C:\Users\username\Desktop\eso1.bmp

CoordMode Pixel  ; Interprets the coordinates below as relative to the screen rather than the active window.
ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, *Icon3 %A_ProgramFiles%\Elder Scrolls Online\Elder Scrolls Online.exe
if ErrorLevel = 2
    MsgBox Could not conduct the search.
else if ErrorLevel = 1
    MsgBox Icon could not be found on the screen.
else
	{
    	MsgBox The icon was found at %FoundX%x%FoundY%.
    	send, {e}
	}

return
The problem is that it does not work. The image is located at C:\Users\username\Desktop\eso1.bmp

The coordinates where the image appears in the game screen are FoundX, FoundY, 814,999, 1102, 1061

The only message that appears is the "Could not conduct the search' which happens only if ErrorLevel = 2

the documentation says the following:
ErrorLevel is set to 0 if the image was found in the specified region, 1 if it was not found, or 2 if there was a problem that prevented the command from conducting the search (such as failure to open the image file or a badly formatted option).
Any help is appreciated.

I got the code from this post viewtopic.php?t=31136
so basically, I am asking exactly what the guy on that post is asking, but the code just does not work!
User avatar
boiler
Posts: 17206
Joined: 21 Dec 2014, 02:44

Re: I need help detecting an image on screen

12 Jan 2023, 04:14

That code doesn’t make sense. If you are looking for the bmp image, what are the lines that follow it that change the CoordMode and search for something else? (I realize someone else wrote it.) That changes the value of ErrorLevel so you lose the result of the search you are actually interested in. Then the conditional statements are meaningless because they’re acting on the wrong result. Remove those two lines.

Also, get rid of the first five lines and the SetKeyDelay line, as well as the CoordMode line that has to do with ToolTip (the one regarding the mouse isn’t needed either if you’re not going to click or move the mouse to the found location). They have nothing to do with this script working. Unfortunately, the OP of that thread wasted a lot of time trying to figure out why that bad code didn’t work.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], just me and 183 guests