Jump to content

Detect an MsgBox


Recommended Posts

I tied an MsgBox to ESC key. And I want to have only one instance of MsgBox regardless of how many times ESC key is pressed. Here's my code:

Func _exit()
   If WinExists($title, "Do you want to quit the setup?") Then
      WinActivate($title, "Do you want to quit the setup?")
   Else
      $msg = MsgBox(262180, $title, "Do you want to quit the setup?")
         If $msg = 6 Then
            ProcessClose($pid)
            Exit 
         EndIf
    EndIf
EndFunc

The script is supposed to focus on the MsgBox if it already exists. But it doesn't. Instead, it creates a new MsgBox every time ESC is pressed.  It seems that it doesn't detect MsgBox as a window. How do I get around that?

Link to comment
Share on other sites

Best way to get help on the forum is to post a working reproducer script! So everyone can test without having to write a lot of code just to get it running.
How do you call function _Exit?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

There must be more, because just by having the HotKeySet and the function your script would end in a split second ... ;)

BTW: Variables $title and $pid are undefined as well!

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Sorry, I didn't think it was necessary because my script is very simple. Here is the whole script:

_singleton("Setup Launcher", 0)
$title = "Setup"
$pid = Run(@ScriptDir & "\setup.exe")
ProcessWait($pid)
While ProcessExists($pid)
    If WinActive("[REGEXPTITLE:Installation;CLASS:#32770]") Then
        HotKeySet("{Esc}", "_Exit")
    Else
        HotKeySet("{Esc}")
    EndIf
WEnd

Func _exit()
   If WinExists($title, "Do you want to quit the setup?") Then
      WinActivate($title, "Do you want to quit the setup?")
   Else
      $msg = MsgBox(262180, $title, "Do you want to quit the setup?")
         If $msg = 6 Then
            ProcessClose($pid)
            Exit 
         EndIf
   EndIf
EndFunc

 

Edited by supraspecies
Link to comment
Share on other sites

Something like this:

#include <Misc.au3>
#include <MsgBoxConstants.au3>

_Singleton("Setup Launcher", 0)
Global $fMsgBox = False
Global $sTitle = "Setup"
Global $iPID = Run(@ScriptDir & "\setup.exe")
; ProcessWait($iPID) ; <== Not needed. You only get the PID when the process exists
While ProcessExists($iPID)
    If WinActive("[REGEXPTITLE:Setup;CLASS:#32770]") Then
        HotKeySet("{Esc}", "_Exit")
    Else
        HotKeySet("{Esc}")
    EndIf
    Sleep(100) ; <== So your script does not eat up all the CPU power
WEnd

Func _Exit()
    ;   If WinExists($sTitle, "Do you want to quit the setup?") Then ; <== Not needed as the MsgBox always stays on top/active
    ;       WinActivate($sTitle, "Do you want to quit the setup?")
    ;   Else
    If $fMsgBox = True Then Return
    $fMsgBox = True
    $iMsg = MsgBox(BitOR($MB_YESNO, $MB_ICONQUESTION, $MB_TASKMODAL), $sTitle, "Do you want to quit the setup?")
    If $iMsg = 6 Then
        ProcessClose($iPID)
        Exit
    EndIf
    $fMsgBox = False
    ;   EndIf
EndFunc   ;==>_Exit

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...