@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: