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
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, 16:02

You were right in how you named the keys, but putting numpad in the filename they way you did isn't right. The reason it uses num is that's a variable equal to the integer index through the loop. How did you name your image files? If you name them Image1.png through Image19.png, it will work when the script is changed back to this:

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
			} until ErrorLevel ; image no longer found
		}
	}
}
return

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

ToolTipOff:
	ToolTip
return
User avatar
RaptorX
Posts: 380
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

28 Mar 2020, 16:49

AeC3 wrote:
26 Mar 2020, 14:07
now what can i do to have two images trigger the same key
this is exciting :D
Simply add the key to the variable list...

For example:

Code: Select all

keys := "1|1|1|2|3|4|5|6|7|8|9|0"
If you do this, the key 1 would be pressed for the first 3 images on the set.

Just add the key to the position you want it to be pressed.

For example:

Code: Select all

keys := "1|2|3|4|5|1|6|7|8|1|9|0"
In that last example The 1 would be pressed the 1st, 6th and 10th time (which might be different images if you so prefer)
Projects:
AHK-ToolKit
Rayleigh001
Posts: 5
Joined: 26 Sep 2021, 05:59

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

26 Sep 2021, 20:15

Hello Iam using the following script before and found out this post, I tried these new codes of yours but it didnt work in my game "exe" (although it works in regular window). Im just wondering if its possible to work on a game app like this old script that Iam using. Iam a complete new noob in ahk and programing and I appreciate any help you can provide.. Thank you.

THIS IS THE OLD SCRIPT IM USING IN MY GAME THAT IS WORKING BUT IT DOESNT HAVE MULTIPLE IMAGESEARCH WHICH THIS POST HAVE.

Code: Select all

#SingleInstance Force
CoordMode, Mouse
CoordMode, Pixel

ClientEXE := "client.exe"
interval := 100
offsetX := 2
offsetY := 2
shades := 50

Gui, +ToolWindow +AlwaysOnTop +HwndMainHWND
Gui, Font, S8 CDefault, Verdana

Gui, Add, Tab3, hwndTabHWND, Search|Options|On Find Actions
Gui, Tab, 1

Gui, Add, GroupBox, section h110 w100, Image
Gui, Add, Picture, hwndPicHWND xp+10 yp+20 h80 w80
Gui, Add, DDL, Disabled y+17 xp-10  w100 Choose1 vimageFile gImageChange, % Images
Gui, Add, Button, Disabled wp+1 hp gSubmit hwndStartStop, Start
Gui, Add, Edit, vLogEdit ys+6 h158 w260 ReadOnly

Gui, Tab, 2
Gui, Add, Text, , Image Folder
Gui, Add, Edit, section r1 Disabled w220 vimgDirectory, 
Gui, Add, Button, ys-1 gSelectImageFolder, Browse...

;Refresh Images
Gui, Add, Button, ys-1 wp gRefreshImages, Refresh

;Search Interval
Gui, Add, Text, x21 yp+30 Section ,Search Interval [ms]
Gui, Add, Edit, number wp vInterval gIntervalChange center, % interval

;Shades
Gui, Add, Text, ys wp x+20, Variation
Gui, Add, Edit, limit3 w100 number center gVariationChange
Gui, Add, UpDown, Range0-255 vShades gVariationChange, % shades

;Killswitch
Gui, Add, Text, ys x+20, Killswitch
Gui, Add, Hotkey, w113 vKillswitch, F7

;Client EXE
Gui, Add, Text, xs Section y+10, Client EXE Name
Gui, Add, Edit, w120 center vClientEXE disabled, % ClientEXE

;SearchScreen
Gui, Add, CheckBox,  ys+23 center vSearchScreen gSearchEntireScreen checked, Search Entire Screen Instead of EXE?

Gui, Tab, 3

;OnFound
Gui, Add, Text, xs Section y+10, Action when image is found:
Gui, Add, DDL, w200 center vFoundAction altsubmit gUpdateVars, Send Key||Mouse Move to Image|Log Only

;StopIfFound
Gui, Add, Text, xs Section y+10, Keep searching if image is found?
Gui, Add, DDL, w200 center vStopIfFound altsubmit gUpdateVars, Stop if the image is found||Continue Searching at Interval

;Show
Gui, Show, Autosize , Image Search

Log("Ready")

return

SearchEntireScreen:
	Gui, Submit, Nohide
	GuiControl, % (SearchScreen ? "Disable" : "Enable"), ClientEXE
Return

ImageChange:
	Gui, Submit, Nohide
	GuiControl,, % picHWND, % imgDirectory "\" imageFile ".png"
	GuiControl, Move, Static1,  h80 w80
Return

IntervalChange:
	Gui, Submit, Nohide
	If !Interval{
	Interval := 1
	GuiControl,,Interval, % Interval
	}
Return

UpdateVars:
	Gui, Submit, Nohide
Return

VariationChange:
	Gui, Submit, Nohide
	GuiControl,,Shades, % Shades
Return

Search:
	;Search a specific window or just a client area?
	If !(SearchScreen){
		WinActivate, % "ahk_exe " ClientEXE
		WinGetPos, cliX, cliY, cliW, cliH, % "ahk_exe " ClientEXE
		ImageSearch, foundX, foundY, % cliX, % cliY, % cliX + cliW, % cliY + cliH, % "*" shades A_Space imgDirectory "\" imageFile ".png"
	} else { 
		ImageSearch, foundX, foundY, 0, 0, % A_ScreenHeight, % A_ScreenWidth, % "*" shades A_Space imgDirectory "\" imageFile ".png"
	}

    If !(ErrorLevel) {
		If (FoundAction = 1)
			Sleep, 100
			Send, a
		If (FoundAction = 2)
			MouseMove, % FoundX, % FoundY, 0
				
		Log("Found " imageFile " at x:" foundX " y:" foundY)
		
		If (StopIfFound = 1)
			GoSub, Submit
    }
Return

Submit:
	Gui, Submit, Nohide
	Toggle := !Toggle
	If (Killswitch <> "")
		Hotkey, % KillSwitch, Submit, % (Toggle ? "ON" : "OFF")
	GuiControl, % Toggle ? "Disable" : "Enable", imageFile
	GuiControl,, % StartStop, % Toggle ? "Stop" : "Start" 
    SetTimer, Search, % (Toggle) ? interval : "Off"
	Log("Search " (Toggle ? "Started" : "Stopped") " - " imageFile)
Return

Log(txt){
	Global LogEdit
	Gui, Submit, Nohide
	FormatTime, time,, H:MM
	GuiControl,, LogEdit, % time " - " txt "`n" LogEdit
}

GuiClose:
GuiEscape:
	ExitApp
Return

SelectImageFolder:
	Gui, -AlwaysOnTop +Disabled
	FileSelectFolder, Folder, % A_Desktop,,Select Image Folder
	Gui, +AlwaysOnTop -Disabled
	Gui, Show
	If ErrorLevel
		Return
	GuiControl,,imgDirectory, % Folder
	Gui, Submit, Nohide
RefreshImages:
	Gosub, Loadimages
	GuiControl,, imageFile , % "|" Images	
	GuiControl, Choose, % TabHWND, 1
	GoSub ImageChange
Return

LoadImages:
	Images := ""
	Loop, Files, % imgDirectory "\*.png"
		Images .= Format("{:Ts}", StrReplace(A_LoopFileName, "." A_LoopFileExt)) "|" (A_Index = 1 ? "|" : "")
	If (Images <> ""){
		GuiControl, Enable, Start
		GuiControl, Enable, ImageFile
		Log("Image List Updated")
	} else {
		GuiControl, Disable, Start
		GuiControl, Disable, ImageFile
		Log("Folder contains no images")
	}
Return

^Esc::Reload
[Mod edit: [code][/code] tags added.]
Last edited by gregster on 26 Sep 2021, 20:18, edited 1 time in total.
Reason: Please use code tags. Thank you!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333, mikeyww and 278 guests