Is it possible to make image search and match to press a key but with 15ish different keys

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AeC3
Posts: 12
Joined: 25 Mar 2020, 19:39

Is it possible to make image search and match to press a key but with 15ish different keys

25 Mar 2020, 19:55

Is it possible to make image search and match to press a key but with 15ish different keys like a loop
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: Is it possible to make image search and match to press a key but with 15ish different keys

25 Mar 2020, 21:20

Yes. Put all 15ish keys in an array and cycle through them each time the image is found.
AeC3
Posts: 12
Joined: 25 Mar 2020, 19:39

Re: Is it possible to make image search and match to press a key but with 15ish different keys

26 Mar 2020, 02:10

Like this
Image 1 = key 1
Image 2 = key 2
And so on
But with a small scan area
Kinda like if this shows up then press this key

Now I will say I'm completely new to this and do not understand fully what this program Is capable of
User avatar
RaptorX
Posts: 379
Joined: 06 Dec 2014, 14:27
Contact:

Re: Is it possible to make image search and match to press a key but with 15ish different keys

26 Mar 2020, 02:54

yes, it's completely possible.

if you know how to use imagesearch you could do something like this:

Code: Select all

keys = a|c|e|b|k

loop parse, keys, |
{
    ImageSearch, OutX, OutY, X1, Y1, X2, Y2, Image%a_index% ;save the images you're looking for, all with the same name but a sequence number at the end for this example to work
    
    if errorlevel
         send %a_loopfield%
}
you can then modify the keys variable easily.

edit:
change x1, x2, y1, y2 in imagesearch to match the region you're searching.
please note that if you're going to search different regions then you must make some changes to the loop
Projects:
AHK-ToolKit
AeC3
Posts: 12
Joined: 25 Mar 2020, 19:39

Re: Is it possible to make image search and match to press a key but with 15ish different keys

26 Mar 2020, 06:23

So if I'm understanding correctly
This does it in a sequence but
I need it to be able to do
Image 1=key 1
Image 10=key 10
Image 9=Key 9
Can that be done

How do you know what to put in x1 x2 y1 y2
User avatar
RaptorX
Posts: 379
Joined: 06 Dec 2014, 14:27
Contact:

Re: Is it possible to make image search and match to press a key but with 15ish different keys

26 Mar 2020, 07:11

Do you have any control as to how to name the image files?

Regarding the region, you might want to use a script to get the x,y points of the places you want to search...

I will give you more info later on, as right now I'm on mobile.
Projects:
AHK-ToolKit
AeC3
Posts: 12
Joined: 25 Mar 2020, 19:39

Re: Is it possible to make image search and match to press a key but with 15ish different keys

26 Mar 2020, 11:59

Code: Select all

keys = a|c|e|b|k

loop parse, keys, |
{
    ImageSearch, OutX, OutY, X1=952, Y1=1150, X2=1089, Y2=1268, Image%a_index% ;save the images you're looking for, all with the same name but a sequence number at the end for this example to work
    
    if errorlevel
         send %a_loopfield%
}

okay so i have the cords but did i do it right ?
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: Is it possible to make image search and match to press a key but with 15ish different keys

26 Mar 2020, 12:16

Remove the "X1=", etc. like below. Also, The images should have a file extension, so you would add that as shown.

Code: Select all

    ImageSearch, OutX, OutY, 952, 1150, 1089, 1268, Image%a_index%.png
If you wanted to make it easier to match up the images to their letters, you could name them Image_a.png, Image_c.png, etc., and change the ImageSearch line to this:

Code: Select all

    ImageSearch, OutX, OutY, 952, 1150, 1089, 1268, Image_%A_LoopField%.png
AeC3
Posts: 12
Joined: 25 Mar 2020, 19:39

Re: Is it possible to make image search and match to press a key but with 15ish different keys

26 Mar 2020, 12:26

i've done now but i have a folder which have all the images named 1,2,3,4,5,6,7,8,9,0,+ but how do i make it so if 6(image) shows up it presses 6(keypress) until it shows a new image
so it would spam it but controllable and be able to toggle it on and off
is it even possible :)
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: Is it possible to make image search and match to press a key but with 15ish different keys

26 Mar 2020, 12:29

Yes, it's very possible. I can describe the logic to you so you can write it. If you're not looking to learn how to write it yourself, perhaps someone will be willing to write it for you.
AeC3
Posts: 12
Joined: 25 Mar 2020, 19:39

Re: Is it possible to make image search and match to press a key but with 15ish different keys

26 Mar 2020, 12:33

i am very interested in learning this but i only "started" yesterday so newbie would be an understatement
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: Is it possible to make image search and match to press a key but with 15ish different keys

26 Mar 2020, 13:04

OK. Try this. It uses the F1 key to set the toggle, which is set to ON to start. (untested)

Code: Select all

keys := "1|2|3|4|5|6|7|8|9|0"
toggle := 1

loop
{
	loop, Parse, keys, |
	{
		ImageSearch, OutX, OutY, 952, 1150, 1089, 1268, Image%a_index%.png
		if !ErrorLevel ; image found
		{
			num := A_Index ; because A_Index will change in the next loop
			key := A_LoopField
			loop
			{
				if toggle
					Send, % key
				ImageSearch, OutX, OutY, 952, 1150, 1089, 1268, Image%num%.png
			} until ErrorLevel ; image no longer found
		}
	}
}
return

F1::
	toggle := !toggle
	ToolTip, % "Toggle is " (toggle ? "ON" : "OFF")
	SetTimer, ToolTipOff, -1500
return

ToolTipOff:
	ToolTip
return
AeC3
Posts: 12
Joined: 25 Mar 2020, 19:39

Re: Is it possible to make image search and match to press a key but with 15ish different keys

26 Mar 2020, 13:28

it is running and i see the tooltip ON and OFF but it does nothing besides that do i need to add a folder path for the images and maybe the names for them
User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: Is it possible to make image search and match to press a key but with 15ish different keys

26 Mar 2020, 13:32

The names of the images need to be Image1.png, Image2.png, etc. (the script is assuming that's how they are named) It currently expects them to be in the same directory as the script. If they're not, then you need to add either the relative path or the absolute path to the file name in both ImageSearch commands.
AeC3
Posts: 12
Joined: 25 Mar 2020, 19:39

Re: Is it possible to make image search and match to press a key but with 15ish different keys

26 Mar 2020, 13:44

i moved the script to my folder with the images and renamed the images to Image5.png etc
changed the toggle button to F4

still nothing maybe i have the coords wrong or the images changes
does it assume to be run in sequence ? because i do not have a 1 and 2 for example




EDIT : i recropped 1 image and it WORKED XD
AeC3
Posts: 12
Joined: 25 Mar 2020, 19:39

Re: Is it possible to make image search and match to press a key but with 15ish different keys

26 Mar 2020, 14:07

now what can i do to have two images trigger the same key
this is exciting :D
AeC3
Posts: 12
Joined: 25 Mar 2020, 19:39

Re: Is it possible to make image search and match to press a key but with 15ish different keys

26 Mar 2020, 15:38

Code: Select all

keys := "1|2|3|4|5|6|7|8|9|0|{Numpad0}|{Numpad1}|{Numpad2}|{Numpad3}|{Numpad4}|{Numpad5}|{Numpad6}|{Numpad7}|{Numpad8}|{Numpad9}"
toggle := 1

loop
{
	loop, Parse, keys, |
	{
		ImageSearch, OutX, OutY, 940, 1130, 1100, 1270, Image%a_index%.png
		if !ErrorLevel ; image found
		{
			num := A_Index ; because A_Index will change in the next loop
			key := A_LoopField
			loop
			{
				if toggle
					Send, % key
				ImageSearch, OutX, OutY, 940, 1130, 1100, 1270, Image%num%.png
				if toggle
					Send, % key
				ImageSearch, OutX, OutY, 940, 1130, 1100, 1270, Image%numpad%.png
			} until ErrorLevel ; image no longer found
		}
	}
}
return

F4::
	toggle := !toggle
	ToolTip, % "Toggle is " (toggle ? "ON" : "OFF")
	SetTimer, ToolTipOff, -1500
return

ToolTipOff:
	ToolTip
return

i've tried to make it so uses numpad too but i think i'm out of my league here :problem:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: RandomBoy, scriptor2016 and 357 guests