Client Losing Focus Which Interupts Script Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
cleetz
Posts: 30
Joined: 04 Feb 2023, 15:09

Client Losing Focus Which Interupts Script

Post by cleetz » 18 Feb 2023, 19:21

Hello Family. I was wondering if someone could provide a code which will allow the client which is being focused on or potentially "at top" of screen ( as I am able to set the clients to be at the top of everything ) to steal focus back automatically if some popup or windows Frame Application or something steals focus. I'm not at a level yet where I have it constructed where the script realizes it has done something, or if it hasnt, it goes back. So as such, if something steals focus and causes a hiccup in my script, it basically ruins the entire performance. The script in general ; Performs a set list of tasks in the game, then once done, rotates clients and repeats the task on another client, then repeats again and again. I would love to be able to keep a flow and prevent anything from stealing focus and messing the script up. Ive been reading up on WinActive etc but I just cant wrap my head around how it works and would love if someone could help me solve it. Thanks Geniuses <3 :wave:

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

Re: Client Losing Focus Which Interupts Script

Post by mikeyww » 18 Feb 2023, 20:14

Code: Select all

; This script keeps a window active
#Requires AutoHotkey v2.0
stay := "ahk_exe notepad.exe"
Loop {
 WinWait stay       ; Wait for the window to exist
 WinSetAlwaysOnTop  ; Set the window on top
 WinWaitNotActive   ; Wait until the window is inactive
 Try WinActivate    ; Activate the window
 SoundBeep 1500
}

cleetz
Posts: 30
Joined: 04 Feb 2023, 15:09

Re: Client Losing Focus Which Interupts Script

Post by cleetz » 19 Feb 2023, 00:30

thank you king

cleetz
Posts: 30
Joined: 04 Feb 2023, 15:09

Re: Client Losing Focus Which Interupts Script

Post by cleetz » 19 Feb 2023, 13:51

hey bossman. With the

stay := "ahk_exe notepad.exe"

do I replace the "ahk_exe notepad.exe" with the name of the client Im using? Like insert the name of it inside the quotation marks?
or do I just leave it and it auto detects whatever client Ive recently clicked on? Is there something Im supposed to insert to make it know which client to stay focused on? the WinSetAlwaysOnTop says its an invalid command so I assume I'm writing it wrong or missing a variable I should add? Thanks so much for Your patience and all the work You do for the people on these forums.

User avatar
RDC
Posts: 112
Joined: 29 Jan 2023, 10:22

Re: Client Losing Focus Which Interupts Script

Post by RDC » 19 Feb 2023, 17:24

As I am extremely new at this myself, I thought I would share what I think I've learned. I'm sure the gurus will quickly correct me if I'm wrong.

The "ahk_exe notepad.exe" you can determine what you need here with Window Spy and for myself, the documentation at https://www.autohotkey.com/docs/v2/misc/WinTitle.htm (link updated to reflect V2 documentation)

You will see the info you need in Window Spy. Examples below show Window Spy while Notepad is active, and Calculator while it is active. Notepad is an easy item to use as an example as you will quickly notice in a lot of the script examples here.

I hope this helps!!
.
image.png
image.png (555.18 KiB) Viewed 375 times
image.png
image.png (560.65 KiB) Viewed 375 times

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

Re: Client Losing Focus Which Interupts Script  Topic is solved

Post by mikeyww » 19 Feb 2023, 17:36

That is correct. The script is just a demonstration with Notepad. You can use any :arrow: WinTitle.

This is a v2 script. If you are using v1, you can install v2 alongside it, or use the v1 version here.

Code: Select all

; This script keeps a window active
#Requires AutoHotkey v1.1.33
#SingleInstance Force
stay := "ahk_exe notepad.exe"
Loop {
 WinWait % stay          ; Wait for the window to exist
 WinSet AlwaysOnTop, On  ; Set the window on top
 WinWaitNotActive        ; Wait until the window is inactive
 Try WinActivate         ; Activate the window
 SoundBeep 1500
}

cleetz
Posts: 30
Joined: 04 Feb 2023, 15:09

Re: Client Losing Focus Which Interupts Script

Post by cleetz » 20 Feb 2023, 13:37

thanks alot. you guys are chill af

Post Reply

Return to “Ask for Help (v1)”