v1 help detect image and mouse click

Ask gaming related questions (AHK v1.1 and older)
Youkkyy
Posts: 2
Joined: 21 Mar 2023, 10:29

v1 help detect image and mouse click

Post by Youkkyy » 21 Mar 2023, 10:33

Hello, I would like to create a function that :

When I click on the wheel of my mouse, the click is also done on all the filled windows.
This function works well.

I wanted to add a function that allows to detect an image on the filled windows, if the image is found, it clicks on it.

But since I added the SearchImageOnAllWindows function, the script gives me an error :
Image

Code: Select all

gameWindows := ["Youk - Dofus 2.51.4.0", "Olokun - Dofus 2.51.4.0"]
searchImage := "C:\Users\Me\Desktop\AHK\pret.png"
searchInterval := 2000 ; temps en millisecondes entre chaque recherche

SetTimer, SearchImageOnAllWindows, %searchInterval%
return

SearchImageOnAllWindows:
{
    CoordMode, Mouse, Screen
    for index, gameWindowTitle in gameWindows {
        WinGet, gameWindowID, ID, %gameWindowTitle%
        WinActivate, ahk_id %gameWindowID%
        ImageSearch, searchX, searchY, 0, 0, A_ScreenWidth, A_ScreenHeight, %searchImage%
        if ErrorLevel = 0 {
            ControlClick,, %gameWindowTitle%, , LEFT,, NA x%searchX% y%searchY%
        }
    }
}

MButton:: ; clique molette de la souris
{
    CoordMode, Mouse, Screen
    for index, gameWindowTitle in gameWindows {
        WinGet, gameWindowID, ID, %gameWindowTitle%
        ControlClick,, %gameWindowTitle%, , LEFT,, NA x%A_CaretX% y%A_CaretY%
    }
}

off
Posts: 176
Joined: 18 Nov 2022, 21:54

Re: v1 help detect image and mouse click

Post by off » 21 Mar 2023, 18:38

Try to remove first and last { } in SearchImageOnAllWindows and put Return after the last }
My Creations
IMG2HotString - Send image file easily with your hotstring!
CtrlSend - A small solution for sending keys to window in background that doesn't accept ControlSend's key
ControlProcess

Youkkyy
Posts: 2
Joined: 21 Mar 2023, 10:29

Re: v1 help detect image and mouse click

Post by Youkkyy » 21 Mar 2023, 19:41

@off

Image

gregster
Posts: 9014
Joined: 30 Sep 2013, 06:48

Re: v1 help detect image and mouse click

Post by gregster » 21 Mar 2023, 23:40

Afaics, if ErrorLevel = 0 { will cause your problem. The one-true-brace style can only applied with If, if you are using the If (expression) syntax. Thus, try

Code: Select all

 if (ErrorLevel = 0) {
PS: In AHK v1, you should usually end your subroutines, like hotkey subroutines and other labels like SearchImageOnAllWindows:, with a return. Otherwise, code execution will fall through and you might get unexpected results - code blocks like { } won't prevent that. In AHK v2, it's a bit different.

Post Reply

Return to “Gaming Help (v1)”