Script Goes To wrong Screen

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
LeoSkeleton
Posts: 1
Joined: 21 May 2024, 11:59

Script Goes To wrong Screen

21 May 2024, 12:13

I have this script but for some reason in the middle of the script it decides to go over and click on my second monitor instead of my first one

Code: Select all

[/#MaxThreadsPerHotkey 2  ; Allow multiple instances of the same hotkey to interrupt each other

StopLoop := false  ; Initialize the variable

F2:: {
    StopLoop := false  ; Reset the variable when F2 is pressed
    Loop
    {
        if (StopLoop)
            break
		Sleep 2000
        Click 404, 174 ;1 icon
		Sleep 2000
		Click 1363, 174 ;2icon
        Sleep 33000
		Click 56, 243 ;1 spel
		Sleep 2000
		Click 1020, 235 ;2 spel
		Sleep 9000
        Click 139, 151 ;1 play
		Sleep 2000
		Click 1103, 138 ;2 play
        Sleep 1500000
		Click 63, 21 ;1 stäng ner
		Sleep 2000
		Click 1022, 18 ;2 stäng ner
		
    }
    return
}

F6::StopLoop := true
]
Attachments
test.ahk
(688 Bytes) Downloaded 6 times
User avatar
mikeyww
Posts: 27261
Joined: 09 Sep 2014, 18:38

Re: Script Goes To wrong Screen

21 May 2024, 12:57

Welcome to this AutoHotkey forum!
Coordinates are relative to the active window's client area unless CoordMode was used to change that.
Source: Click - Syntax & Usage | AutoHotkey v2
Run Window Spy to see the coordinates.

Throughout your function, there might be a series of multiple, different active windows as the script progresses through the statements.
RussF
Posts: 1301
Joined: 05 Aug 2021, 06:36

Re: Script Goes To wrong Screen

21 May 2024, 13:01

I see that you don't have a CoordMode statement. By default, all mouse coordinates are relative to the active window - not to the screen. Is it possible that a window on your other screen gains focus in the middle of your script?

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

Re: Script Goes To wrong Screen

21 May 2024, 13:10

In v2, coordinates are relative to the active window's client area unless CoordMode is used to change that.
RussF
Posts: 1301
Joined: 05 Aug 2021, 06:36

Re: Script Goes To wrong Screen

21 May 2024, 13:15

You are correct @mikeyww, a subtle, but important distinction and an oversight on my part.

Russ

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: joedf, Madison01, vmech, wineguy and 49 guests