1
votes

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 )<<<<
2
I would recommend either using WinWait or ShellHook. The latter has the upside of allowing an event-driven implementation. In other words, the process can totally rest or do something else whilst waiting for the window. In my opinion, even a waiting loop would be fine if your script has nothing else to do. If you want a quick solution, I suggest using WinWait. - MCL
Thanks, my thought's exactly from my independent research but there's something going wrong with my implementation. I have added code snippets up above. Can you take a look and help me out? Thanks! - theAliasOfAlias
Have a look at the docs. You are using a timeout of 0 which means it will wait for 0.5 seconds. In other words, it will send enter almost immediately, no matter which window is active. - MCL
Interesting, so you recommend waiting for a second as a minimum? The purpose was for the box to clear just as soon as it becomes active so it doesn't break or delay the scanning process at Point of Sale - so you think that is the issue, not that I've implemented it incorrectly? - theAliasOfAlias
I recommend waiting indefinitely. Why just one second or 10 or 1000? - MCL

2 Answers

1
votes

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...

0
votes

how about this?:

F12:: 
  WINDOWEXPLORER: 
    WinWaitActive, Windows Explorer,, 0.01 
    if ErrorLevel { 
      Goto WINDOWEXPLORER 
    } else { 
      ; SoundBeep 4500, 30
      Return 
    }