getting file name from pictures on screen

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
android7
Posts: 2
Joined: 17 Jun 2018, 09:42

getting file name from pictures on screen

17 Jun 2018, 10:09

The title may be a little misleading, so here's the long story:
I have bunch of pictures in a directory. I want to make a script scanning for those pictures on screen, and when one of them appears, Send file name of the picture.

Code: Select all

Pics := []
Loop, Files, *.bmp, R
{
    Pics.Push(LoadPicture(A_LoopFileFullPath))
}

while(true)
{	for i in Pics{
		ImageSearch, FoundX, FoundY,X,Y,I,J,Pics[i]
		if ErrorLevel = 0
		Send, ;name of picture and {Enter}
		}
	}
User avatar
DyaTactic
Posts: 221
Joined: 04 Apr 2017, 05:52

Re: getting file name from pictures on screen

17 Jun 2018, 13:37

I would save the filename in the same Pics array, making it a 2D array. Like so:

Code: Select all

Pics := []
Loop, Files, *.bmp, R
{
    Pics.Push([LoadPicture(A_LoopFileFullPath), A_LoopFileFullPath])
}

while(true)
{	for i in Pics{
		ImageSearch, FoundX, FoundY,X,Y,I,J,Pics[i, 1]
		if ErrorLevel = 0
		{
			Send, % Pics[i , 2] . "{Enter}"	;name of picture and {Enter}
			}
		
		}
	}
Does it do what you want?

You may want to use SplithPath to splith the filename in filename, extension, folder etc. prior to Sending it.
android7
Posts: 2
Joined: 17 Jun 2018, 09:42

Re: getting file name from pictures on screen

18 Jun 2018, 10:10

Thanks, thats exactly what I wanted.
I had some mistakes in my previous post, namely missing handler for Pics and i being used in ImageSearch, so here's the working version for future reference.

Code: Select all

Pics := []
Loop, Files, *.bmp, R	
{
    Pics.Push([LoadPicture(A_LoopFileFullPath), A_LoopFileFullPath])
}
while(true)
{
	for c in Pics{
		ImageSearch, FoundX, FoundY,X,Y,I,J, % "HBITMAP:*" Pics[c , 1] 
		if ErrorLevel = 0
		{
			Name = % Pics[c , 2] 
			SplitPath, Name,,,, NameShort
			Send, % NameShort . "{Enter}"
			}
		
		}
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww, RussF and 309 guests