#IfWinActive not working

Get help with using AutoHotkey and its commands and hotkeys
partof
Posts: 95
Joined: 16 Jan 2016, 08:38

#IfWinActive not working

29 Dec 2017, 13:23

I want to send a hotkeys to a specific log in popup.

Here is my code:

Code: Select all

#IfWinActive, ahk_class Credential Dialog Xaml Host
	Send, {TAB 2}
	Send, {Enter}
But the tabs and the enter are still send to any Windows open (chrome, np++,MS Word...).

With Window Spy, I got this info for Windows Tilte, Class and Process of the pop up :

Code: Select all

Windows Security
ahk_class Credential Dialog Xaml Host
ahk_exe explorer.exe
So I also tried "#IfWinActive, ahk_exe explorer.exe" (not ideal because it' s not specific enough) and "#IfWinActive Windows Security"
I have also tried to replace "#IfWinActive" by "IfWinActive" and to use the normal If:

Code: Select all

#If WinActive("ahk_class Credential Dialog Xaml Host")
	Send, {TAB 2}
	Send, {Enter}
#If
Here is the pop up I want to send the command to (it's the login pop up of a network drive in Windows10:
[img]https://images.scdn8.secure.raxcdn.com/ ... 50e889.jpg
[/img]
A_AhkUser
Posts: 1076
Joined: 06 Mar 2017, 16:18
GitHub: AAhkUser
Location: France

Re: #IfWinActive not working

29 Dec 2017, 13:32

Creates context-sensitive hotkeys and hotstrings.
source: #IfWinActive / #IfWinExist

Code: Select all

#IfWinActive ahk_exe notepad.exe
a::MsgBox % A_ThisHotkey ; < this works: we've defined a double-colon hotkey, yet #If directives affect hotkeys and hotstrings
return
Try this instead:

Code: Select all

if (WinActive("ahk_exe notepad.exe")) {
	Send, {TAB 2}
	Send, {Enter}
} ; contrary to whats' happen using the #if directive, you must but in a block, enclosed in braces the code whose execution should depends on the fact that the condition is satisfied
partof
Posts: 95
Joined: 16 Jan 2016, 08:38

Re: #IfWinActive not working

30 Dec 2017, 09:33

Super! It's working, thanks so much!
I can even use the windows title:

Code: Select all

if (WinActive("Windows Security")){
	Send, {TAB 2}
	Send, {Enter}
}

Return to “Ask For Help”

Who is online

Users browsing this forum: andrewvanmarle, Bing [Bot], flyingDman, Google [Bot], Gully, joefiesta, Mrl72 and 205 guests