Can't identify target with IfWinNotActive

Ask gaming related questions (AHK v1.1 and older)
fosterfast
Posts: 4
Joined: 26 Jan 2024, 09:48

Can't identify target with IfWinNotActive

26 Jan 2024, 18:15

Hi Everyone,

I'm sorry if this is obvious but I really have tried for many hours.

I want AHK to open JoyToKey then gzdoom.exe in that order which it does fine (I had to add sleep in the middle or JoyToKey would stay front of screen). Then, if I close gzdoom.exe I want AHK to close JoyToKey which I'm trying to use IfWinNotActive. However, it seems AHK is not identifying gzdoom.exe as active so it closes JoyToKey automatically before gzdoom.exe is closed manually.

Can someone please point out my error. I have also attached the winspy for gzdoom. Thank you in advance!

Code: Select all

Run, C:\Users\pc\Dropbox\Gaming\Z_Apps and Controllers\Joy2Key\JoyToKey_Doom Classic.lnk, C:\Users\pc\Dropbox\Gaming\Z_Apps and Controllers\Joy2Key
Sleep, 1000
Run, C:\Users\pc\Dropbox\Gaming\LaunchBox\Games\PC Games\Doom\Doom Project Brutality_1_2_Final_Master\gzdoom_doom2.exe.lnk, C:\Users\pc\Dropbox\Gaming\LaunchBox\Games\PC Games\Doom\Doom Project Brutality_1_2_Final_Master
IfWinNotActive, gzdoom.exe
Process, Close, JoyToKey.exe
Return

[Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]

[Mod action: Topic moved from "Scripts and Functions (v2) > Gaming)" for two reason: (1) this is AHK v1 code and the main section is for v2, and (2) "Scripts and Functions" is for sharing working scripts with others, not for seeking help with your scripts.]
User avatar
boiler
Posts: 17157
Joined: 21 Dec 2014, 02:44

Re: Can't identify target with IfWinNotActive

26 Jan 2024, 18:28

fosterfast wrote: I have also attached the winspy for gzdoom.
You have not, so please try again. Please also see the moderator notes added to your post. Thank you.
fosterfast
Posts: 4
Joined: 26 Jan 2024, 09:48

Re: Can't identify target with IfWinNotActive

26 Jan 2024, 23:10

Sorry boiler. I'm having trouble attaching files... Details are:
PB_Introduction - Doom 2: Hell on Earth
ahk_class Main Window
ahk_exe gzdoom.exe
ahk_pid 16564
ahk_id 134042
User avatar
boiler
Posts: 17157
Joined: 21 Dec 2014, 02:44

Re: Can't identify target with IfWinNotActive

26 Jan 2024, 23:34

This line is not correct:

Code: Select all

IfWinNotActive, gzdoom.exe

That would mean that the title of the window starts with gzdoom.exe. That’s the process name — not the title. The way you use that in a WinTitle parameter is to precede it with ahk_exe as described at the linked page.

Code: Select all

IfWinNotActive, ahk_exe gzdoom.exe

By the way, IfWinNotActive has been deprecated, so you really should use this:

Code: Select all

if !WinActive("ahk_exe gzdoom.exe")
fosterfast
Posts: 4
Joined: 26 Jan 2024, 09:48

Re: Can't identify target with IfWinNotActive

27 Jan 2024, 01:19

Thanks again. I understand re if

Code: Select all

!WinActive("ahk_exe gzdoom.exe")
. Unfortunately, it's still not closing JoyToKey when I exit Doom. Here is the script (I also tried WinClose using ahk_id):

Code: Select all

Run, C:\Users\pc\Dropbox\Gaming\Z_Apps and Controllers\Joy2Key\JoyToKey_Doom Classic.lnk, C:\Users\pc\Dropbox\Gaming\Z_Apps and Controllers\Joy2Key
Sleep, 1000
Run, C:\Users\pc\Dropbox\Gaming\LaunchBox\Games\PC Games\Doom\Doom Project Brutality_1_2_Final_Master\gzdoom_doom2.exe.lnk, C:\Users\pc\Dropbox\Gaming\LaunchBox\Games\PC Games\Doom\Doom Project Brutality_1_2_Final_Master
if !WinActive("ahk_exe gzdoom.exe")
Process, Close, JoyToKey.exe
Return
User avatar
boiler
Posts: 17157
Joined: 21 Dec 2014, 02:44

Re: Can't identify target with IfWinNotActive

27 Jan 2024, 02:36

That’s because your script just executes each line and finsishes. You have nothing telling it to wait or to keep checking or anything. It excutes the “if” line immediately, and since gzdoom isn’t even open yet, it does nothing and ends. You could do something like this:

Code: Select all

Run, C:\Users\pc\Dropbox\Gaming\Z_Apps and Controllers\Joy2Key\JoyToKey_Doom Classic.lnk, C:\Users\pc\Dropbox\Gaming\Z_Apps and Controllers\Joy2Key
Sleep, 1000
Run, C:\Users\pc\Dropbox\Gaming\LaunchBox\Games\PC Games\Doom\Doom Project Brutality_1_2_Final_Master\gzdoom_doom2.exe.lnk, C:\Users\pc\Dropbox\Gaming\LaunchBox\Games\PC Games\Doom\Doom Project Brutality_1_2_Final_Master
WinWait, ahk_exe gzdoom.exe
WinWaitClose, ahk_exe gzdoom.exe
Process, Close, JoyToKey.exe
Return
fosterfast
Posts: 4
Joined: 26 Jan 2024, 09:48

Re: Can't identify target with IfWinNotActive

27 Jan 2024, 03:18

Thanks very much for this boiler! Legend.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 34 guests