ImageSearch works great on one computer, not on another

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
MikeOrlando
Posts: 22
Joined: 05 Jun 2017, 08:18

ImageSearch works great on one computer, not on another

05 Jan 2021, 21:43

Hello,

I created a script using ImageSearch to click on a button on a web page in Chrome. Works great on my Windows 7 computer I used for testing. Moved it to my Windows 10 laptop that I want to use it on and it doesn't appear to click the image. Same version of AHK. Windows 7 vs 10. In testing it ran on my desktop vs. the new computer C:\AHK. Only difference I can think of

Code: Select all

#NoEnv  
SendMode Input  
SetWorkingDir %A_ScriptDir%  

SetTitleMatchMode, 1
SetTitleMatchMode, Fast
#SingleInstance force
CoordMode, Mouse, Client



;PREPARE CHROME WINDOW
WinActivate, Incident		
Sleep 100
WinMaximize, Incident		
Sleep 100
Send {Ctrl Down}0{Ctrl Up}	
Sleep 100
ClipSaved := Clipboard		; Save User Clipboard Content




;LAUNCH REPORT
Loop, 30
{
	ImageSearch, Printx, Printy, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, print_icon_target.png 
	If (ErrorLevel = 0) 				
	{
		%Printx%+=5
		%Printy%+=5
		Click, %Printx%, %Printy% 		
		Break
	}
	Else
	{
		Sleep 1000
	}
}

Any suggestions what direction I can try?
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: ImageSearch works great on one computer, not on another

05 Jan 2021, 21:46

are you using the same image on both? If not I suggest you take an image on the win 10 and try that.
User avatar
mikeyww
Posts: 26942
Joined: 09 Sep 2014, 18:38

Re: ImageSearch works great on one computer, not on another

05 Jan 2021, 21:58

I agree. Different displays often provide different renderings of text, possibly vector graphics, etc., so you would want an actual bitmap. In addition, Windows 10 uses different fonts, so if the image has any basis in fonts, it could easily be different.
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: ImageSearch works great on one computer, not on another

05 Jan 2021, 23:28

Note: The offset clicking is not working the way you think it is:

Code: Select all

Printx := 1
Printy := 1

%Printx%+=5
%Printy%+=5

MsgBox % Printx A_Tab Printy
Not a fix for your OP just showing another issue.

HTH
MikeOrlando
Posts: 22
Joined: 05 Jun 2017, 08:18

Re: ImageSearch works great on one computer, not on another

06 Jan 2021, 09:14

I did originally try using the same image that I had created using the Windows 7 snip tool on the Windows 10 machine. When that did not work I did try to re-create the image using snip in Windows 10 and thought I may have seen it click, but completely in the wrong place, it is difficult to see as it happens so quickly.

I will have to look at the offset example that was sent to better understand how that works and if that is now my issue after updating the image. The offset part seemed to work in Windows 7, but I never printed the results to a message box to see what they actually were so I will do that when I get to my desk.

Thanks for the suggestions, much appreciated.
User avatar
mikeyww
Posts: 26942
Joined: 09 Sep 2014, 18:38

Re: ImageSearch works great on one computer, not on another

06 Jan 2021, 09:26

If you are using ImageSearch followed by Click, then you would typically want the CoordMode to be the same for Pixel and Mouse. If they differ as in your script, unexpected results often occur. The active window differs from the client window.
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: ImageSearch works great on one computer, not on another

06 Jan 2021, 10:04

MikeOrlando wrote:
05 Jan 2021, 21:43
I created a script using ImageSearch to click on a button on a web page in Chrome. Works great on my Windows 7 computer I used for testing. Moved it to my Windows 10 laptop that I want to use it on and it doesn't appear to click the image. Same version of AHK. Windows 7 vs 10...
Any suggestions what direction I can try?
Here are 3 things that might help:

1) Use variation. Referred to as *n (variation) in the help document.

ImageSearch, Printx, Printy, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *25 print_icon_target.png

Variation is from 0 to 255. 0 is very strict, 255 is the most loose and accepts anything. See if you can find a number that matches the picture, but not gives wrong results.

2) Try creating an image to search for that is at the same resolution on the different computer.

So maybe you have 2 or more images that the script checks for. Which it searches for depends on screen resolution (A_ScreenWidth, A_ScreenHeight).

3) WinActivate the specific application (this case Chrome) and/or specific tab, then search on it for the image.

Usually ahk_exe makes for the simplest way. WinActivate, ahk_exe Chrome.exe. Tabs are actual windows. You can see this by using WindowSpy.ahk (located in the default installation folder).

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb and 308 guests