Clicking Key If detected image

Ask gaming related questions (AHK v1.1 and older)
Altros
Posts: 4
Joined: 02 Apr 2020, 16:12

Clicking Key If detected image

02 Apr 2020, 16:38

Hello, I wanted to ask, if its possible to make autohotkey that detect image that will appear on screen and then click some keys.
I know that there is ImageSearch, but I don't know how to write the script. For example, when the image appear on screen it detect it and click key. Is there a way to do it and how?
Sorry for the trouble, im new in this :D
Altros
Posts: 4
Joined: 02 Apr 2020, 16:12

Re: Clicking Key If detected image

02 Apr 2020, 17:10

I made something like this:
numpad5::
imagesearch, x, y, 0, 0, 4000, 3000, 1.png
if (ErrorLevel = 0)
send {Space Up}
sleep 10
send {Space Down}

But I want it to work like everytime its on screen, not when Im clicking numpad5
(4000x3000 cause 2 screens)
User avatar
Yakshongas
Posts: 590
Joined: 21 Jan 2020, 08:41

Re: Clicking Key If detected image

03 Apr 2020, 07:48

Try with this:

Code: Select all

SetBatchLines -1
Loop
{
	image:
	ImageSearch, posX, posY, 0, 0, A_ScreenWidth, A_ScreenHeight, 1.png
	If (ErrorLevel=0)
	{
		SendEvent, {Space Down}
		Sleep, 10
		SendEvent, {Space Up}
	}
	Else
	{
		goto, image
	}
}
Keep in mind that the screen Width and Height you are using is HUGE and it will probably take a while just to identify the image also the script may freeze.
Please mark your topics as solved if you don't need any further help. ✅

Need a little more help? Discord : Yakshongas#9893 🕹
Altros
Posts: 4
Joined: 02 Apr 2020, 16:12

Re: Clicking Key If detected image

03 Apr 2020, 08:22

I watched some tutorials and did the loop and GUI, but another problem is that after failed imagesearch I want another ImageSearch, but its not founding it, I have image in folder with script and on screen. Here's the full script for now:
https pastebin.com /05X4zyei Broken Link for safety
(dont know how to paste full code like you)
I changed sendevents for now to msgbox to test it.
I want something like if image1 is on screen it click space, if there is not image1, it search for image2 and click space 2 times
User avatar
Yakshongas
Posts: 590
Joined: 21 Jan 2020, 08:41

Re: Clicking Key If detected image

03 Apr 2020, 08:46

Try with this it works for me. (You forgot to use Else if instead of 2 if's)

Code: Select all

#SingleInstance,Force
SetWorkingDir,%A_ScriptDir%
CoordMode,Mouse,screen
CoordMode,Pixel,Screen
Gui, Font, clime
Gui, Add, Text, x90 y10, Testing
Gui, Add, Button, x90 y30 w70 h30 gstart, Start
Gui, Add, Button, x90 y70 w70 h30 gstop, Stop
Gui, Add, Button, x90 y110 w70 h30 gexit, Exit
Gui, +AlwaysOnTop
Gui, Color, Black
Gui, Show, w250 h160,Test
return
 
GuiClose:
    ExitApp
    return
 
 
 
start:
    ImageSearch, PosX1, PosY1, 0, 0, A_ScreenWidth, A_ScreenHeight, image1.png
    if (ErrorLevel=0)
        {  
            msgbox, found1
        }
    Else if (ErrorLevel=1) or (ErrorLevel=2)
        {
            ImageSearch, PosX2, PosY2, 0, 0, A_ScreenWidth, A_ScreenHeight, image2.png
            if (ErrorLevel=0)
                {  
                    msgbox, found2
                }
            Else if (ErrorLevel=1) or (ErrorLevel=2)
                {
                    msgbox, not found  
                }
        }
    return
 
stop:
    return
   
exit:
    ExitApp
    return
 
 
 
 
 
 
^x::ExitApp
Also to paste as code use this.
Attachments
NewCanvas1.png
NewCanvas1.png (19.36 KiB) Viewed 636 times
Please mark your topics as solved if you don't need any further help. ✅

Need a little more help? Discord : Yakshongas#9893 🕹
Altros
Posts: 4
Joined: 02 Apr 2020, 16:12

Re: Clicking Key If detected image

03 Apr 2020, 08:55

I added you on Discord (Scutii_#1538)
I changed it but it doing the same thing, it thinks that there is no image2.
Can you maybe help me on Discord? It will be faster than here. If I find solution I will paste it here later

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 112 guests