Imagesearch region + execute keybind if true [Post deleted]

Ask gaming related questions (AHK v1.1 and older)
Blick
Posts: 5
Joined: 03 Oct 2018, 19:37

Imagesearch region + execute keybind if true [Post deleted]

03 Oct 2018, 20:08

:D FIXED :), DELETE THREAD PLEASE!

Nextron edit: Restored content:
What I'm trying to do is have AHK search the area on the screen I specify for an image that is changing almost every 1-2 seconds. every time it sees that image it will then spam press keyboard number I assigned to the image, if the image changes then AHK does the same thing in loop. If it doesn't have anything in the region then it will idle until an image comes up. Any help is really appreciated thank you so much! This is what I have so far as to what i'm trying to do but im kind of stuck on what do do next.
I'm also trying to have it only working while I hold down a specified button on my keyboard like "j" or anything like that.

ImageSearch, OutputVarX, OutputVarY, 936, 668, 980, 715, C:\Users\A\Downloads\WoW\Garrote.png
ImageSearch, OutputVarX, OutputVarY, 936, 668, 980, 715, C:\Users\A\Downloads\WoW\envenom.png
ImageSearch, OutputVarX, OutputVarY, 936, 668, 980, 715, C:\Users\A\Downloads\WoW\Mutilate.png
ImageSearch, OutputVarX, OutputVarY, 936, 668, 980, 715, C:\Users\A\Downloads\WoW\rupture.png
ImageSearch, OutputVarX, OutputVarY, 936, 668, 980, 715, C:\Users\A\Downloads\WoW\vanish.png
ImageSearch, OutputVarX, OutputVarY, 936, 668, 980, 715, C:\Users\A\Downloads\WoW\vendetta.png

This big icon in the middle that is changing is the region I set it to search for if i'm correct.
This is the video
https://streamable.com/hl8qu
Last edited by Blick on 04 Oct 2018, 12:21, edited 2 times in total.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Imagesearch region + execute keybind if true / need help

04 Oct 2018, 04:05

Code: Select all

#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Pixel

*j::SetTimer WatchSpells, 10
*j Up::SetTimer WatchSpells, Off

WatchSpells() {
	static X1 := 936, Y1 := 668, X2 := 980, Y2 := 715 
	, SPELL_KEYMAP := {"Garrote": "q"
					 , "envenom": "w"
					 , "Mutilate": "e"
					 , "rupture": "r"
					 , "vanish": "t"
					 , "vendetta": "y"}

	for spell, key in SPELL_KEYMAP
	{
		ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\A\Downloads\WoW\" spell ".png"
		if !ErrorLevel
			Send % key
	}
}
Blick
Posts: 5
Joined: 03 Oct 2018, 19:37

Re: Imagesearch region + execute keybind if true / need help

04 Oct 2018, 05:47

:D
Nextron edit: Restored content:

Code: Select all

#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Pixel

*j::SetTimer WatchSpells, 10
*j Up::SetTimer WatchSpells, Off

WatchSpells() {
	static X1 := 936, Y1 := 668, X2 := 980, Y2 := 715 
	, SPELL_KEYMAP := {"Garrote": "q"
					 , "envenom": "w"
					 , "Mutilate": "e"
					 , "rupture": "r"
					 , "vanish": "t"
					 , "vendetta": "y"}

	for spell, key in SPELL_KEYMAP
	{
		ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\A\Downloads\WoW\" spell ".png"
		if !ErrorLevel
			Send % key
	}
}
Do I have to change anything in your code to make it work? Sorry for my ignorance i'm brand new to AHK.
It didn't work if so. I might need to change my pics to be smaller for AHK to recognize the image inside x1y1y1y2
Thank you so much for the help, really looking forward to learning more.

*EDIT*
Worked perfectly. Thank you so much for the help!!
Last edited by Blick on 04 Oct 2018, 12:19, edited 1 time in total.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Imagesearch region + execute keybind if true / need help

04 Oct 2018, 08:13

u can change the coordinates, the spell names/image files, and the keys to which spells are bound(q,w,e,r,t,y in this case, likely something else in urs)
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: FIXED!DELETE THREAD PLEASE!

19 Oct 2018, 17:47

fixed, delete thread please................... ughh for fucks sake, i dont even
https://autohotkey.com/forumrules/
Image
Brick wrote: Hey man the script you posted on the thread works perfectly but it's just spamming the output key when image found a little bit too slow and i'm wantint to make it a bit faster. Was wondering where I could change that in the script?
This is a video of how slow the output is. Other than that thanks for being a great person and helping the community!
https://streamable.com/iyjh7

Code: Select all

#IfWinActive World of Warcraft
#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Pixel

*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off

WatchSpells() {
static X1 := 936, Y1 := 668, X2 := 980, Y2 := 715 
, SPELL_KEYMAP := {"Garrote": "1"
, "envenom": "7"
, "Mutilate": "9"
, "rupture": "8"
, "vanish": "="
, "vendetta": "-"
, "toxicblade": "0"
, "cobra": "1"
, "crows": "9"
, "killcommand": "2"
, "wrath": "3"
, "aspect": "5"
, "barbed": "0"
, "chimera": "8"
, "barbed2": "0"
, "barbed3": "0"
, "barbed4": "0"
, "anh": "3"
, "aura": "2"
, "chaos": "3"
, "dance": "8"
, "eyebeam": "4"
, "sweep": "8"
, "demon": "9"}

for spell, key in SPELL_KEYMAP
{
ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\A\Downloads\o\" spell ".png"
if !ErrorLevel
Send % key
}
}
swagfag wrote: ur bottleneck is the ImageSearch, which is computationally very expensive. To increase its speed, narrow its search space, or increase its variance setting(although this might result in failures to match accurately).
Furthermore, im no wow aficionado but it would seem youve added spells belonging to different classes all in the same script. While convenient for u perhaps, this causes avoidable delays. It makes little sense to needlessly check for hunter spells while playing a rogue is what im getting at - either make separate scripts or load the images manually according to what youre playing atm(eg via different hotkeys)
Another optimization would be to do away with image searching altogether and resort to something else, eg PixelGetColor. If u can uniquely identify each spell by a single pixel, this approach would be viable. See this img(look for 1 pixel, instead of imagesearching a whole rectangle)
Look at this similar thread also: https://autohotkey.com/boards/viewtopic.php?f=5&t=48122
U can use an addon maybe like tellmewhen or something to assign each spell a different brightly colored square(r, g, b, cyan, magenta, etc) and PixelGetColor on it, if finding unique pixel in the original textures isnt feasible
Brick wrote: Hey this was the code that you helped me out with and very grateful for but 1 more question regarding this if you could help me out. I'm wondering how to input another scan area on the screen for the script to look for and be optimized so it wouldn't slow anything down. I know how to get coordinates but I don't know where in the AHK script to input them to not screw anything up.
Any help would be appreciated and grateful as always!
ive no recollection of the original question and have nothing to cross reference it with, since u overwrote the thread. it sounds to me like wrapping the imagesearch loop in a function would do the trick and then pass it whatever coords it needs to look at:

Code: Select all

#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Pixel

#IfWinActive World of Warcraft
*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off

WatchSpells() {
	static SPELL_KEYMAP := {"Garrote": "1"}

	ImgSearch(936, 668, 980, 715, SPELL_KEYMAP)
	ImgSearch(100, 100, 200, 200, SPELL_KEYMAP)
}

ImgSearch(X1, Y1, X2, Y2, SpellKeyMap) {
	for spell, key in SpellKeyMap
	{
		ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\A\Downloads\o\" spell ".png"
		if !ErrorLevel
			Send % key
	}
}
Blick
Posts: 5
Joined: 03 Oct 2018, 19:37

Re: FIXED!DELETE THREAD PLEASE!

20 Oct 2018, 13:32

swagfag wrote:
19 Oct 2018, 17:47
fixed, delete thread please................... ughh for fucks sake, i dont even
https://autohotkey.com/forumrules/
Image
Brick wrote: Hey man the script you posted on the thread works perfectly but it's just spamming the output key when image found a little bit too slow and i'm wantint to make it a bit faster. Was wondering where I could change that in the script?
This is a video of how slow the output is. Other than that thanks for being a great person and helping the community!
https://streamable.com/iyjh7

Code: Select all

#IfWinActive World of Warcraft
#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Pixel

*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off

WatchSpells() {
static X1 := 936, Y1 := 668, X2 := 980, Y2 := 715 
, SPELL_KEYMAP := {"Garrote": "1"
, "envenom": "7"
, "Mutilate": "9"
, "rupture": "8"
, "vanish": "="
, "vendetta": "-"
, "toxicblade": "0"
, "cobra": "1"
, "crows": "9"
, "killcommand": "2"
, "wrath": "3"
, "aspect": "5"
, "barbed": "0"
, "chimera": "8"
, "barbed2": "0"
, "barbed3": "0"
, "barbed4": "0"
, "anh": "3"
, "aura": "2"
, "chaos": "3"
, "dance": "8"
, "eyebeam": "4"
, "sweep": "8"
, "demon": "9"}

for spell, key in SPELL_KEYMAP
{
ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\A\Downloads\o\" spell ".png"
if !ErrorLevel
Send % key
}
}
swagfag wrote: ur bottleneck is the ImageSearch, which is computationally very expensive. To increase its speed, narrow its search space, or increase its variance setting(although this might result in failures to match accurately).
Furthermore, im no wow aficionado but it would seem youve added spells belonging to different classes all in the same script. While convenient for u perhaps, this causes avoidable delays. It makes little sense to needlessly check for hunter spells while playing a rogue is what im getting at - either make separate scripts or load the images manually according to what youre playing atm(eg via different hotkeys)
Another optimization would be to do away with image searching altogether and resort to something else, eg PixelGetColor. If u can uniquely identify each spell by a single pixel, this approach would be viable. See this img(look for 1 pixel, instead of imagesearching a whole rectangle)
Look at this similar thread also: https://autohotkey.com/boards/viewtopic.php?f=5&t=48122
U can use an addon maybe like tellmewhen or something to assign each spell a different brightly colored square(r, g, b, cyan, magenta, etc) and PixelGetColor on it, if finding unique pixel in the original textures isnt feasible
Brick wrote: Hey this was the code that you helped me out with and very grateful for but 1 more question regarding this if you could help me out. I'm wondering how to input another scan area on the screen for the script to look for and be optimized so it wouldn't slow anything down. I know how to get coordinates but I don't know where in the AHK script to input them to not screw anything up.
Any help would be appreciated and grateful as always!
ive no recollection of the original question and have nothing to cross reference it with, since u overwrote the thread. it sounds to me like wrapping the imagesearch loop in a function would do the trick and then pass it whatever coords it needs to look at:

Code: Select all

#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Pixel

#IfWinActive World of Warcraft
*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off

WatchSpells() {
	static SPELL_KEYMAP := {"Garrote": "1"}

	ImgSearch(936, 668, 980, 715, SPELL_KEYMAP)
	ImgSearch(100, 100, 200, 200, SPELL_KEYMAP)
}

ImgSearch(X1, Y1, X2, Y2, SpellKeyMap) {
	for spell, key in SpellKeyMap
	{
		ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\A\Downloads\o\" spell ".png"
		if !ErrorLevel
			Send % key
	}
}
Hey i'm trying to do this but it keeps telling me that theres an error missing "}" on line 18. Tried fixing it but still won't execute for me. What am I doing wrong?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: FIXED!DELETE THREAD PLEASE!

20 Oct 2018, 14:25

what ive posted, as is, executes without throwing:

Code: Select all

#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Pixel

#IfWinActive World of Warcraft
*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off

WatchSpells() {
	static SPELL_KEYMAP := {"Garrote": "1"}

	ImgSearch(936, 668, 980, 715, SPELL_KEYMAP)
	ImgSearch(100, 100, 200, 200, SPELL_KEYMAP)
}

ImgSearch(X1, Y1, X2, Y2, SpellKeyMap) { ; <-- line 18 in this script
	for spell, key in SpellKeyMap
	{
		ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\A\Downloads\o\" spell ".png"
		if !ErrorLevel
			Send % key
	}
} ; is this perhaps missing??
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: FIXED!DELETE THREAD PLEASE!

20 Oct 2018, 14:49

@blick If you ever post another question and then overwrite it again as you have done here and i find out. you will be banned
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
Blick
Posts: 5
Joined: 03 Oct 2018, 19:37

Re: FIXED!DELETE THREAD PLEASE!

20 Oct 2018, 21:59

swagfag wrote:
20 Oct 2018, 14:25
what ive posted, as is, executes without throwing:

Code: Select all

#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Pixel

#IfWinActive World of Warcraft
*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off

WatchSpells() {
	static SPELL_KEYMAP := {"Garrote": "1"}

	ImgSearch(936, 668, 980, 715, SPELL_KEYMAP)
	ImgSearch(100, 100, 200, 200, SPELL_KEYMAP)
}

ImgSearch(X1, Y1, X2, Y2, SpellKeyMap) { ; <-- line 18 in this script
	for spell, key in SpellKeyMap
	{
		ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\A\Downloads\o\" spell ".png"
		if !ErrorLevel
			Send % key
	}
} ; is this perhaps missing??
You were right, it was because I was missing that at the end! Thank you.
I made the scan areas and the images smaller but they are still outputting the keys pretty slowly. Any way to speed up the output? When only scanning one area the output is very fast.
Blick
Posts: 5
Joined: 03 Oct 2018, 19:37

Re: FIXED!DELETE THREAD PLEASE!

20 Oct 2018, 22:06

tank wrote:
20 Oct 2018, 14:49
@blick If you ever post another question and then overwrite it again as you have done here and i find out. you will be banned
I didn't know if this was against the game rules and didn't want anyone else to do the same thing as i'm doing for this game in case this was going to get people banned. I'm not 100% so if I get banned i'm on a throw away account and I won't care as much as another player who has spent 3+ years on his/her account. Even if someone else will be using this script for learning it wouldn't be advised to be used on any games as the anti-cheat might pick up this and get you banned.
Ankhy
Posts: 11
Joined: 26 Feb 2018, 19:25

Re: Imagesearch region + execute keybind if true [Post deleted]

10 Dec 2020, 12:32

If I would like to loop this, instead of holding a button, where would I need to put the loop in? =\ (Newbie here)
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Imagesearch region + execute keybind if true [Post deleted]

10 Dec 2020, 15:55

Ankhy wrote:
10 Dec 2020, 12:32
If I would like to loop this, instead of holding a button, where would I need to put the loop in? =\ (Newbie here)
Change:

Code: Select all

*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off
to:

Code: Select all

*1::SetTimer WatchSpells, % (t:=!t) ? 10 : "Off"
Now it will toggle.
Ankhy
Posts: 11
Joined: 26 Feb 2018, 19:25

Re: Imagesearch region + execute keybind if true [Post deleted]

11 Dec 2020, 02:16

Xtra wrote:
10 Dec 2020, 15:55
Ankhy wrote:
10 Dec 2020, 12:32
If I would like to loop this, instead of holding a button, where would I need to put the loop in? =\ (Newbie here)
Change:

Code: Select all

*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off
to:

Code: Select all

*1::SetTimer WatchSpells, % (t:=!t) ? 10 : "Off"
Now it will toggle.
Amazing, thank you :)

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: Rohwedder and 87 guests