ImageSearch and custom GUI Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
tonkomnom
Posts: 37
Joined: 25 Jul 2018, 02:53
Contact:

ImageSearch and custom GUI

25 Jul 2018, 03:15

I've created a custom GUI to look for a specific control and tick or untick it depending on its current state (ControlGet, ControlClick, etc does not work). The ticking and unticking works fine as long as the GUI is to the left of the control I'm searching for. I've tried countless variations of CoordMode settings but can't get it to work, it either doesn't find the image and/or always clicks relative to the GUI instead of the screen.

Code: Select all

Gui,+AlwaysOnTop
gui, add, button, x15 y5 h20 w120 gsub1, Tick
gui, add, button, x15 y30 h20 w120 gsub2, Untick
gui, add, button, x40 y60 h20 w70 greload, Reload
gui, add, button, x40 y85 h20 w70 gexit, Exit Script
gui, show, x380 y100 w150 h120
Return

sub1:
 {
 	CoordMode, Pixel, Relative
	ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, %A_ScriptDir%\tickempty.png
	if ErrorLevel = 2
	    MsgBox Could not conduct the search.
	else if ErrorLevel = 1
		MsgBox Icon could not be found on the screen.
	else
		MouseGetPos, posx, posy
	    MouseClick, Left, Foundx + 5, FoundY +5
	    WinActivate, %A_ScriptName%
	    MouseMove, posx, posy
	Return
 }
Return

sub2:
 {
   CoordMode, Pixel, Relative
   ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, %A_ScriptDir%\tick.png
	if ErrorLevel = 2
	    MsgBox Could not conduct the search.
	else if ErrorLevel = 1
		MsgBox Icon could not be found on the screen.
	else
		MouseGetPos, posx, posy
	    MouseClick, Left, Foundx + 5, FoundY +5
	    WinActivate, %A_ScriptName%
	    MouseMove, posx, posy
	Return
 }
Return

reload:
Reload

guiclose:
exit:
 {
   exitapp
 }
Return
egocarib
Posts: 100
Joined: 21 May 2015, 18:21

Re: ImageSearch and custom GUI  Topic is solved

25 Jul 2018, 10:39

You need to use CoordMode, Pixel, Screen. More importantly, you also need to use CoordMode, Mouse, Screen, because you also use mouse click commands.

See CoordMode.

In addition, if you have multiple monitors you will have to make additional adjustments to your script.
User avatar
tonkomnom
Posts: 37
Joined: 25 Jul 2018, 02:53
Contact:

Re: ImageSearch and custom GUI

26 Jul 2018, 04:24

Awesome, it's working as intended now, thank you! Not having any issues with the second screen though.
egocarib
Posts: 100
Joined: 21 May 2015, 18:21

Re: ImageSearch and custom GUI

26 Jul 2018, 12:48

To elaborate, A_ScreenWidth and A_ScreenHeight get the dimensions from only your primary monitor. If you want to search across multiple monitors, there are some notes on the linked doc pages about how to search the entire desktop area.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], NinjoOnline and 247 guests