WinExist not recognizing Outlook pop-up

Get help with using AutoHotkey and its commands and hotkeys
timg11

WinExist not recognizing Outlook pop-up

09 Dec 2016, 16:56

I use a Loop in Autohotkey to close various dialogs. I have a working section of code that looks like this to identify a specific pop-up window and send Enter:

Code: Select all

	If WinExist("ahk_exe treesize.exe") and WinExist("ahk_class TMessageForm") and WinExist("Error")
			{
			WinActivate, Error
			Send {Enter} ;  OK to dialog
			Sleep 10
			}
I tried adding a similar structured code segment for the Outlook pop-up:

Code: Select all

	If WinExist("ahk_exe OUTLOOK.EXE") and WinExist("ahk_class 32770") and WinExist("Microsoft Outlook") 
			{
			WinActivate, Microsoft Outlook
			Send !a
			Send {Tab}{Down}{Down}{Down}{Down}{Tab}
			Send {Enter} ;  OK to dialog
			Sleep 10
			}
This code does not work. It does not act when the window appears.
Here's the window spy results and the window itself.
Image Link: http://imgur.com/jVUQz16

What am I missing?
Guest

Re: WinExist not recognizing Outlook pop-up

10 Dec 2016, 05:23

Try

Code: Select all

Title := "Microsoft Outlook" . " " . "ahk_class 32770" . " " . "ahk_exe OUTLOOK.EXE"

If WinExist(Title) {
	WinWait      , % Title
	WinActivate  , % Title
	WinWaitActive, % Title
	Send, !a
	Send, {Tab}{Down}{Down}{Down}{Down}{Tab}
	Send, {Enter}  ; OK to dialog
	Sleep, 10
}
Return
timg11
Posts: 20
Joined: 10 Dec 2016, 14:09

Re: WinExist not recognizing Outlook pop-up

10 Dec 2016, 14:53

@Guest, thanks for the suggestion. Unfortunately it does not work. I edited my script and inserted your code.
I got the same result. The window appears, but AutoHotKey is not triggered to send the keys.

I kept playing around, and found that it will work if I remove the ahk_class qualifier.
I was worried that other Outlook windows would incorrectly trigger the AHK script, so I wanted to make it specific as possible.

So this code works and detects the dialog:

Code: Select all

	If WinExist("ahk_exe OUTLOOK.EXE") and WinExist("Microsoft Outlook") 
			{
			WinActivate, Microsoft Outlook
			Send !a
			Send {Tab}{Down}{Down}{Down}{Down}{Tab}
			Send {Enter} ;  OK to dialog
			Sleep 10
			}
The problem here is this code triggers all the time - when Outlook runs or displays other dialogs it executed. There needs to be further qualification but distinguishing by ahk_class doesn't work.
After reading the help for WinExist, which says "WinText: If present, this parameter must be a substring from a single text element of the target window (as revealed by the included Window Spy utility)," I thought about adding a qualification for the button text such as Deny:

Code: Select all

	If WinExist("ahk_exe OUTLOOK.EXE") and WinExist("Deny")  and WinExist("Microsoft Outlook") 
			{
			WinActivate, Microsoft Outlook
			Send !a
			Send {Tab}{Down}{Down}{Down}{Down}{Tab}
			Send {Enter} ;  OK to dialog
			Sleep 10
			}
But this does not work - the window is not detected.

I may be confused by the multiple forms of syntax for WinExist. The help shows this form:

Code: Select all

IfWinExist [, WinTitle, WinText,  ExcludeTitle, ExcludeText]
but in the example, we see this form:

Code: Select all

if WinExist("ahk_class Notepad") or WinExist("ahk_class" . ClassName)
I can't find the specific syntax and usage for the second form. Maybe the use of WinText is not supported in the second form:

Code: Select all

WinExist("Deny")
Guest

Re: WinExist not recognizing Outlook pop-up

10 Dec 2016, 16:46

timg11 wrote:Unfortunately it does not work. I edited my script and inserted your code.
I use this a lot and it works.

Code: Select all

Title := "Microsoft Outlook" . " " . "ahk_class 32770" . " " . "ahk_exe OUTLOOK.EXE"

WinWait      , % Title
WinActivate  , % Title
WinWaitActive, % Title
Send, !a
Send, {Tab}{Down 4}{Tab}
Send, {Enter}  ; OK to dialog
Sleep, 10
lexikos
Posts: 7085
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: WinExist not recognizing Outlook pop-up

10 Dec 2016, 18:36

timg11,

The syntax for WinExist() is shown at the top, under the syntax for IfWinNotExist.

The examples and your code call WinExist() multiple times and combine the results with logical-OR or logical-AND. These are only valid in expressions. IF with a function() call is automatically If-expression.

Calling WinExist() multiple times and combining with logical-AND will only tell you if a window matching each criteria exists; it will not verify that all three are the same window. For your first example, if WinExist("Error ahk_exe treesize.exe ahk_class TMessageForm") would tell you if a single window matching all three criteria exists. The window title must come first. This is exactly the same as IfWinExist, Error ahk_exe treesize.exe ahk_class TMessageForm.

The first parameter of WinExist() is clearly WinTitle. It can't be both WinTitle and WinText. WinText is the second parameter.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Dante, DavidP, geloSemen, Google [Bot], Lem2001, mikeyww, nestea2k, pgarza and 50 guests