ahk_id doesn't work for WinActive? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
john_c
Posts: 493
Joined: 05 May 2017, 13:19

ahk_id doesn't work for WinActive?

15 Jul 2018, 17:54

The code is simple, but I'm surprised it doesn't work. Why?

Code: Select all

#SingleInstance, Force

Gui, +HwndGuiId
Gui, Add, Text,, %GuiId%
Gui, Show, w300 h200 Center, Test
Return

F1::
    If WinActive("Test")              ; Works fine
    If WinActive("Test ahk_id GuiId") ; Doesn't work
    If WinActive("ahk_id GuiId")      ; Doesn't work
        SoundBeep, 500, 500
Return
ssh003
Posts: 4
Joined: 15 Jul 2018, 05:34

Re: ahk_id doesn't work for WinActive?

15 Jul 2018, 18:07

Code: Select all

#SingleInstance, Force

Gui, +HwndGuiId
Gui, Add, Text,, %GuiId%
Gui, Show, w300 h200 Center, Test
Return

F1::
    IfWinActive,Test
        SoundBeep, 500, 500
Return

F2::
    IfWinActive,Test ,%Guild%
        SoundBeep, 500, 500
return

F3::
    IfWinActive,ahk_exe Test.exe
        SoundBeep, 500, 500
return
have you try this code?
john_c
Posts: 493
Joined: 05 May 2017, 13:19

Re: ahk_id doesn't work for WinActive?

15 Jul 2018, 18:16

@ssh003 I think these examples aren't relivant here. Also, as I understand, 2nd example isn't correct - there should not be comma between "Test" and "%GuiId%".
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: ahk_id doesn't work for WinActive?

15 Jul 2018, 18:35

try adding SetTitleMatchMode, 2
gregster
Posts: 8989
Joined: 30 Sep 2013, 06:48

Re: ahk_id doesn't work for WinActive?  Topic is solved

15 Jul 2018, 18:37

GuiID is a variable in this case. In your function calls that don't work, you treat it as a literal string. It works as a variable:

Code: Select all

#SingleInstance, Force

Gui, +HwndGuiId
Gui, Add, Text,, %GuiId%
Gui, Show, w300 h200 Center, Test
Return

F1::
    If WinActive("Test ahk_id " GuiId) 
        SoundBeep, 500, 500
Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], haomingchen1998, mikeyww and 233 guests