How to AutoHotKey to monitor constantly for a particular pop-up and run a script when that pop-up appears

StackOverflow https://stackoverflow.com/questions/17914690

Question

We have an annoying pop up that occurs in our Point of Sale system, that always has the same Window Title and Window Message. I would like to create a script that monitors constantly for this window to pop up, and presses enter immediately when it does.

I realize I could use a loop that runs a check for the window every 500ms and then executes the script if the window is present, but I'm thinking there must be SOME way where AHK can monitor continuously without being on a short timed loop. Any past experience is well appreciated! Thank you!

P.S. I looked into the #persistent tag, but I don't think that really does what I'm looking for.

Additional note: I continued my own line of research and found WinWait, but it's not working when the pop up box appears! Can you let me know what I'm doing wrong? Here's the script that I added to my AHK file:

WinWaitActive, Message, Number of Kits,0
{
    Send {Enter}
}
Return

And here is the capture from the Windows Inspector:

>>>>>>>>>>( Window Title & Class )<<<<<<<<<<<
Message
ahk_class TMessForm

>>>>>>>>>>>>( Mouse Position )<<<<<<<<<<<<<
On Screen:  1219, 438  (less often used)
In Active Window:   765, 7

>>>>>>>>>( Now Under Mouse Cursor )<<<<<<<<

Color:  0xF7F3F7  (Blue=F7 Green=F3 Red=F7)

>>>>>>>>>>( Active Window Position )<<<<<<<<<<
left: 454     top: 431     width: 491     height: 148

>>>>>>>>>>>( Status Bar Text )<<<<<<<<<<

>>>>>>>>>>>( Visible Window Text )<<<<<<<<<<<
&Ok
1
Number of Kits

>>>>>>>>>>>( Hidden Window Text )<<<<<<<<<<<

>>>>( TitleMatchMode=slow Visible Text )<<<<

>>>>( TitleMatchMode=slow Hidden Text )<<<<
Était-ce utile?

La solution

I've been fighting a few popups with a timer that is executed every second for years. If it doesn't work right away, you'd just have to change the IfWinExist to match your window.

SetTimer, CheckWin, 1000
return


CheckWin:
SetTitleMatchMode, 2
IfWinExist, ahk_class TMessForm, Number of Kits
{
   WinClose 

   ; alternatively, write code to activate window
   ; then send Enter as in your example

   TrayTip, Popup-Killer,Window killed,3, 17
   return
}
return

BTW, I really like MCL's Shell Hook idea from the comments...

Autres conseils

how about this?:

F12:: 
  WINDOWEXPLORER: 
    WinWaitActive, Windows Explorer,, 0.01 
    if ErrorLevel { 
      Goto WINDOWEXPLORER 
    } else { 
      ; SoundBeep 4500, 30
      Return 
    }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top