How to react to a popup?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Wpq
Posts: 14
Joined: 02 Mar 2021, 04:15
Location: France

How to react to a popup?

Post by Wpq » 02 Mar 2021, 04:24

I have a popup coming from an application that requires to press OK so that the application can run. I would like to automate that with AutoHotkey.

I found on the old forum a perfect solution (https://autohotkey.com/board/topic/74282-how-to-react-to-appearance-of-a-window/):

Code: Select all

DetectHiddenWindows, On
Hwnd := WinExist(A_ScriptFullPath)
DllCall( "RegisterShellHookWindow", UInt,Hwnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
Return

ShellMessage( wParam,lParam )
{
	WinGetClass, Class, ahk_id %lParam%
	If (Class = "Notepad")
        MsgBox Action goes here!
        return	
}
It is accepted by AutoHotkey but there is no reaction when opening Notepad. I believe that it must be modified for my environment (Windows 10, AHK 1.1.33.02, the post was from 2014) but I have no idea how.

Is such a solution that uses a hook still possible?
User avatar
mikeyww
Posts: 27177
Joined: 09 Sep 2014, 18:38

Re: How to react to a popup?

Post by mikeyww » 02 Mar 2021, 07:44

It worked when I tested it. The message box might appear before the Notepad window, putting Notepad in the foreground.
Wpq
Posts: 14
Joined: 02 Mar 2021, 04:15
Location: France

Re: How to react to a popup?

Post by Wpq » 02 Mar 2021, 11:54

mikeyww wrote:
02 Mar 2021, 07:44
It worked when I tested it. The message box might appear before the Notepad window, putting Notepad in the foreground.
In fact when I launch Notepad (and the window appears) - nothing happens. I am a novice in AHK but my understanding is that a message box should pop up somewhere.
Is there a way to "debug" AHK, or trace the calls to make sure everything is executed (I reloaded my main script where all my AHK settings are - and in which I added the code block from the question)
User avatar
mikeyww
Posts: 27177
Joined: 09 Sep 2014, 18:38

Re: How to react to a popup?

Post by mikeyww » 02 Mar 2021, 12:28

Probably, but you'll need someone who knows more about DLL! Others on the forum here will know. You might also try running as admin.

Within the function, you could add a MsgBox or two, to see whether the function is being called, and what window classes you are seeing.

Is this your entire script-- nothing else in it-- and you have no other scripts running? Have you saved and run the script, so that its icon is visible in the system tray?
Post Reply

Return to “Ask for Help (v1)”