Image Search and working directory issue?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
japankid3000
Posts: 43
Joined: 14 Nov 2015, 09:58

Image Search and working directory issue?

10 Jan 2016, 05:45

Hello i am trying to use Image Search to click a .png image on a website but i save the .png image with a snipping tool and save it to my autohotkey folder but it never clicks the .png so i am assuming the .png is not in the right directory so how do i solve this, i don't even know the current directory?

Code: Select all

f1::
Loop {
	ImageSearch,x,y,0,0,%A_ScreenWidth%,%A_ScreenHeight%,#Include %A_ScriptDir% "\exampleimage.png"
	If !ErrorLevel
		Click % x+10 " " y+10
	Sleep 500
}
just me
Posts: 9560
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Image Search and working directory issue?

10 Jan 2016, 07:24

Where did you find this syntax?
#Include is an own command respectively a directive.
Also, ImageSearch uses command syntax by default, and I don't think that the file name actually contains double-quotes.

Code: Select all

	ImageSearch,x,y,0,0,%A_ScreenWidth%,%A_ScreenHeight%, %A_ScriptDir%\exampleimage.png
?
japankid3000
Posts: 43
Joined: 14 Nov 2015, 09:58

Re: Image Search and working directory issue?

10 Jan 2016, 23:11

https://autohotkey.com/boards/viewtopic.php?f=5&t=12806

That is where this started.

I tryed running the script but it still won't click my exampleimage.png.

I have my autohotkey folder on my desktop and stored the .png image in there, is that the working directory ?
just me
Posts: 9560
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Image Search and working directory issue?

11 Jan 2016, 02:51

ImageFile
The file name of an image, which is assumed to be in %A_WorkingDir% if an absolute path isn't specified.
%A_ScriptDir%\exampleimage.png or % A_ScriptDir "\exampleimage.png" are absolute pathes, so the working directory doesn't matter. You should try to check the ErrorLevel set by ImageSearch.
japankid3000
Posts: 43
Joined: 14 Nov 2015, 09:58

Re: Image Search and working directory issue?

11 Jan 2016, 06:48

I just read up on ImageSearch and Errorlevel but i still can not get it to work for this it always gives me Errorlevel = 2

Do i use SysGet to get %A_ScreenWidth%,%A_ScreenHeight% and change it to the actual number?

Do i need to change any of these parameters ,x,y,0,0,%A_ScreenWidth%,%A_ScreenHeight%,

Sorry i am new........

Code: Select all

f1::
	CoordMode Pixel  ; Interprets the coordinates below as relative to the screen rather than the active window.
ImageSearch,x,y,0,0,%A_ScreenWidth%,%A_ScreenHeight%, %A_ScriptDir%\exampleimage.png
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%.
User avatar
boiler
Posts: 17337
Joined: 21 Dec 2014, 02:44

Re: Image Search and working directory issue?

11 Jan 2016, 08:12

You don't need % around the A_ScreenWidth and A_ScreenHeight variables since those ImageSearch parameters can be expressions. It's not a problem, though. Just noting it.

Your MsgBox command refers to variables FoundX and FoundY, while you actually are using variable names x and y in your ImageSearch command.

None of the above would explain why you would be getting an ErrorLevel of 2, though. Have you double-checked that your reference image file name is spelled exactly as you show in the script and that the file is in the same directory as the script?
japankid3000
Posts: 43
Joined: 14 Nov 2015, 09:58

Re: Image Search and working directory issue?

13 Jan 2016, 18:14

%A_ScriptDir%\exampleimage.png or % A_ScriptDir "\exampleimage.png" are absolute pathes, so the working directory doesn't matter.
That person said the directory doesn't matter isn't that conflicting with you saying it might not be in the right directory.....

The image is saved to c:/scripting but none of these will not work for me.

Code: Select all

f1::
	CoordMode Pixel  
ImageSearch,x,y,0,0,1920,1080, %A_ScriptDir%\clickme.png
Click, %foundx%, %foundy%

Code: Select all

f1::
	CoordMode Pixel
ImageSearch,x,y,0,0,1920,1080, C:\Scripting\clickme.png
Click, %foundx%, %foundy%

Code: Select all

f1::
ThisImageVariable := "C:\Scripting\clickme.png"
	CoordMode Pixel  
ImageSearch,x,y,0,0,1920,1080, %ThisImageVariable%
Click, %foundx%, %foundy%
That is exactly how i try the code, just to be clear i want to send a mouseclick to the image. (*6 hours invested in this) i should probaley give up with scripting :(
User avatar
boiler
Posts: 17337
Joined: 21 Dec 2014, 02:44

Re: Image Search and working directory issue?

14 Jan 2016, 01:23

Again, you are using x and y in ImageSearch but then you use foundx and foundy in the Click command. Use x and y in both places or use foundx and foundy in both places. You can't return the location of the image search into variables called x and y and then click on foundx and foundy and expect it to work.

You should also set CoordMode for the mouse to make sure it using the same as what you set for pixel.
japankid3000
Posts: 43
Joined: 14 Nov 2015, 09:58

Re: Image Search and working directory issue?

14 Jan 2016, 12:32

I finally got it too work. thanks boiler

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Dart Vanya and 120 guests