ImageSearch - problem with shifted X/Y

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Duzers
Posts: 3
Joined: 23 May 2022, 06:24

ImageSearch - problem with shifted X/Y

Post by Duzers » 23 May 2022, 06:59

I try to search image on screen, but I get strange coordinates of this image.
I have two monitors.
1. 3840x2160, scale 150%
2. 2560x1440, scale 125%

It is also strange, because below code retrieves the bounding coordinates of the specified monitor:
1. 0,0,2560,1440 (why not 3840,2160???)
2. 3072,0,5120,1152

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

SysGet, Mon2, Monitor, 2
MsgBox, Left: %Mon2Left% -- Top: %Mon2Top% -- Right: %Mon2Right% -- Bottom %Mon2Bottom%.
Furthemore, coordinates of searched image are shifted.
image.png
image.png (381.39 KiB) Viewed 301 times
Code for search image:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.


SetTitleMatchMode, 2

CoordMode, ToolTip, screen
CoordMode, Mouse, screen
CoordMode, Pixel, screen 

;ImageSearch, FoundX, FoundY, Mon2Left, Mon2Top, VirtualWidth, VirtualHeight,  G:\testahk.png 
ImageSearch, FoundX, FoundY, Mon2Left, Mon2Top, A_ScreenWidth, A_ScreenHeight,  *50 G:\testahk.png 

if ErrorLevel = 2
	MsgBox Could not conduct the image search.
else if ErrorLevel = 1
{
		MsgBox Image not found
		ExitApp
		Return
}
Click, %FoundX%, %FoundY%
MsgBox %FoundX% %FoundY%
ExitApp
Return
Thanks for any idea.

User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: ImageSearch - problem with shifted X/Y

Post by WalkerOfTheDay » 23 May 2022, 08:18

I think the color variations of *50 might be to high. Also the different scaling on both monitors could be an issue (not sure).

What happens if you do this (works for me):

Code: Select all

^1::																				; <<< added, press CTRL-1 to start the script

SetTitleMatchMode, 2

CoordMode, ToolTip, screen
CoordMode, Mouse, screen
CoordMode, Pixel, screen 

ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight,  *10 testimage.png 			; <<< changed. 100 % image 

if ErrorLevel = 2
	MsgBox Could not conduct the image search.
else if ErrorLevel = 1
{
		MsgBox,,, Image not found ! Trying for second image., 2
		Sleep, 100																; <<< added, otherwise for it isn't found
		ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight,  *10 testimage_125.png 	; <<< added, 125 % image
		if ErrorLevel = 1
			MsgBox, Nope
}
mousemove, %foundX%, %foundy%, 50 														; <<< added, to see if the cursor moves to the correct position
Click, %FoundX%, %FoundY%
MsgBox %FoundX% %FoundY%
;ExitApp
Return

iseahound
Posts: 1444
Joined: 13 Aug 2016, 21:04
Contact:

Re: ImageSearch - problem with shifted X/Y

Post by iseahound » 23 May 2022, 12:35

Also the different scaling on both monitors could be an issue
It probably is the issue.

Duzers
Posts: 3
Joined: 23 May 2022, 06:24

Re: ImageSearch - problem with shifted X/Y

Post by Duzers » 24 May 2022, 09:46

iseahound wrote:
23 May 2022, 12:35
Also the different scaling on both monitors could be an issue
It probably is the issue.
With program "Automatic Mouse and Keyboard" was pretty similar problem and after my intervention they corrected this.
I have to tested AutoHotKey on second computer with clean system.

Duzers
Posts: 3
Joined: 23 May 2022, 06:24

Re: ImageSearch - problem with shifted X/Y

Post by Duzers » 24 May 2022, 11:00

SOLUTION:

OK, accidentally I found a solution.
I run scripts from Directory Opus, and for this file manager I changed DPI settings, something like this (System Enhanced):
image.png
image.png (139.78 KiB) Viewed 213 times
After that my script took over DPI settings from Directory Opus and it didn't work properly.

Post Reply

Return to “Ask for Help (v1)”