#IfWinActive does not support variables? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
afe
Posts: 433
Joined: 06 Dec 2018, 04:36

#IfWinActive does not support variables?

15 Jun 2019, 00:22

Hello,
I encountered a problem when the hotkey was only started when the script's own window was active.
I found that #IfWinActive does not support %Var%. How to solve it?

If the script is run again and no ahk_pid %pid% is added, does the hotkey conflict between the two processes?

Thanks.

Code: Select all

#SingleInstance Off

Gui, Show, h300 w400, TEST
Process, Exist
pid := ErrorLevel
return

#IfWinActive TEST ahk_pid %pid%                      ; Error here
Enter::MsgBox OK
return
afe
Posts: 433
Joined: 06 Dec 2018, 04:36

Re: #IfWinActive does not support variables?

15 Jun 2019, 01:04

Edit:

Thank you very much. It work fine.

Code: Select all

Gui, Show, h300 w400, TEST
Process, Exist
pid := ErrorLevel
return

#If WinActive("TEST" "ahk_pid" . pid)
    Enter::MsgBox OK
return
Last edited by afe on 15 Jun 2019, 01:23, edited 2 times in total.
Hellbent
Posts: 572
Joined: 23 Sep 2017, 13:34

Re: #IfWinActive does not support variables?

15 Jun 2019, 01:10

afe wrote:
15 Jun 2019, 01:04
Like this? It does not work.

Code: Select all

Gui, Show, h300 w400, TEST
Process, Exist
pid := ErrorLevel
return

#If WinActive(TEST ahk_pid %pid%)
    Enter::MsgBox OK
return

ahk_pid is a string so it needs to be wrapped in quotes and pid doesn't need the %%.
Not sure "Test" is doing anything.
Never tried using the process id in WinActive(), but I assume it should work.

Code: Select all

#If (WinActive("ahk_pid" pid))
***Edit***
Helgef beat me to it.
User avatar
jeeswg
Posts: 6469
Joined: 19 Dec 2016, 01:58
Location: UK

Re: #IfWinActive does not support variables?

15 Jun 2019, 01:23

An alternative solution is to use GroupAdd, and #IfWinActive with ahk_group,
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
afe
Posts: 433
Joined: 06 Dec 2018, 04:36

Re: #IfWinActive does not support variables?

15 Jun 2019, 01:26

Thank you very much. It work fine.

Return to “Ask For Help”

Who is online

Users browsing this forum: aifritz, bennybroseph, kronos90, tmplinshi and 216 guests