Question about WinActive and WinActivate not working

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
BrockPlaysFortnite
Posts: 84
Joined: 06 Nov 2021, 08:47

Question about WinActive and WinActivate not working

Post by BrockPlaysFortnite » 19 Jan 2022, 04:50

Hey guys, random question on WinActivate being used in unison with WinActive. I noticed the top code did not work when it came to activating the window but the bottom code did. Is there a specific reason in my code or do some programs behave differently when doing it the top way?

Code: Select all

if not WinActive("ahk_exe voicemeeter8.exe")
	WinActivate
	
if not WinActive("ahk_exe voicemeeter8.exe")
	WinActivate ahk_exe voicemeeter8.exe

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

Re: Question about WinActive and WinActivate not working

Post by boiler » 19 Jan 2022, 05:10

According to the WinTitle documentation, it should work the same as the example shown:

Code: Select all

if WinExist("Untitled - Notepad")
{
    WinActivate ; Use the window found by WinExist.
    WinMaximize ; Same as above.
    Send, Some text.{Enter}
    return
}

I personally never use a blank WinTitle, even though scripts can perform faster without it since they don’t have to identify matching windows again. I’d rather repeat the criteria so it’s always clear which window I’m acting on. Sometimes other commands for other windows might be added in between and result in undesired behavior. I just also never really trusted it. It looks like you have confirmed my suspicions.

User avatar
BrockPlaysFortnite
Posts: 84
Joined: 06 Nov 2021, 08:47

Re: Question about WinActive and WinActivate not working

Post by BrockPlaysFortnite » 19 Jan 2022, 05:43

Yea I saw the same thing but wanted to confirm it wasn't me messing up the syntax. Agree that its better practice to never leave it empty
Fortnite Youtuber BrockPlaysFortnite :D | AHK completely redefined the way I do things. What used to take me hours to do over and over can now be done with the click of a button. Don't give up! It's worth learning it front to back :wave:
(Note: I'm still a noob so my code may suck sometimes and there is almost assuredly a better way to do it)

Post Reply

Return to “Ask for Help (v1)”