A script that detects an image on screen then toggles

Ask gaming related questions (AHK v1.1 and older)
Dreamsy
Posts: 1
Joined: 13 Feb 2024, 05:28

A script that detects an image on screen then toggles

Post by Dreamsy » 13 Feb 2024, 05:34

So i wanna make a ahk that sends SPACE key when picture is found and then loops back to wait for it to reappear Sofar ive tried to just get it to send SPACE when the picture appears but it never does send space. I tried replacing sending space with a msgbox, and it did say the picture is found but it never sent space...
and it should keep searching until script is toggeled off but i dont have that part yet... can someone guide me in the right direction or fix the script?
Its for a game fishing automation and the hook should be on the colored bar when sending space so i took a snip of it but the hook is moving pretty fast and maybe it doesnt react fast enought?
code:

Code: Select all

image = img.png
If !FileExist(image)
 MsgBox, 48, Error, File not found.`n`n%image%
F3::
CoordMode, Pixel
ImageSearch, x, y, 0, 0, A_ScreenWidth, A_ScreenHeight, %image%
If ErrorLevel
Return
Else Send, {space}
Return
This is the code and i will also add the img.png(https://i.stack.imgur.com/HkSGA.png) Please help :)

[Mod edit: Added [code][/code] tags. Please use them yourself when posting code!]

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: A script that detects an image on screen then toggles

Post by mikeyww » 15 Feb 2024, 20:34

Welcome to this AutoHotkey forum!

Since you are having trouble with the search, I recommend starting with a new three-line test script. On the first line, set your CoordMode. On the second line, do the search; hard-code the image path. On the third line, display the value of ErrorLevel. The value will be 0, 1, or 2.

This approach will help you to identify the problem more quickly and directly.

Post Reply

Return to “Gaming Help (v1)”