Code not working on a specific window

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
MissilePenguin
Posts: 1
Joined: 29 Mar 2023, 11:06

Code not working on a specific window

Post by MissilePenguin » 29 Mar 2023, 11:37

The Description:
This is my current AHK script. I'm a newb so it might be a little clunky, but I made a website to test it on quickly, and that worked fine. The idea is have it click a button to launch something, wait 14 seconds for that thing to launch, and then screenshot the thing, and close it down. Ideally it does that over and over again until I say stop (or until 100 loops).

The problem:
The problem is that whenever I try to actually use the program that is called by WinActivate, or even if I dont use WinActivate and just run the script while focused on the specific launcher, it doesn't do the click functions properly. It still takes the screenshots, but wont move the mouse or click. Again, it works fine if I'm focused on google chrome or Windows Explorer, it's just the specific thing that I want to run it on. The program is called Haze launcher. I have tried doing window relative coords and screen relative coords, and neither work. Any help would be greatly appreciated.

Code: Select all

#Include CaptureScreen.ahk

^+r:: ; This creates a hotkey of Control+Shift+R

xCoord := 3690
yCoord := 123

; Set the delay time in milliseconds
delay_time := 14000

; Set the number of times to loop
LoopCount := 100

CoordMode, pixel, Screen

; Loop through the specified number of times
Loop %LoopCount% {
	WinActivate, ahk_id 328264

	Sleep 50

    ; Click the button at the specified coordinate
    Click %xCoord%, %yCoord%

    ; Wait for the delay time
    Sleep %delay_time%

    ; Take a screenshot
	CaptureScreen(3, 0, "ScarygirlSS\TestShot" A_Now ".png")
	; first parameter indicates full screen capture
	; change 2nd parameter to 1 if you want mouse cursor in image
	; change to desired path. can also change .png to .jpg or other

	
	WinActivate, ahk_id 328264

	Click %xCoord%, %yCoord%


    ; Wait for a short time before continuing the loop
    Sleep 5000
	
	
}

esc::ExitApp
[Mod edit: Moved topic to AHK v1 help.]

User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: Code not working on a specific window

Post by boiler » 29 Mar 2023, 14:10

There are two issues I see right away. There may be more.

You set CoordMode for Pixel, but not Mouse, so the clicks are relative to the active window, not the screen. What are the coordinates in your script based on?

You are using a fixed number for the HWND of the window. HWNDs change every time a window is created. The actual number of any particular window should not be hard-coded into your script. Use a different way of identifying your window with the WinTitle parameter.

Post Reply

Return to “Ask for Help (v1)”