supraspecies Posted March 25, 2017 Share Posted March 25, 2017 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 More sharing options...
water Posted March 25, 2017 Share Posted March 25, 2017 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
supraspecies Posted March 25, 2017 Author Share Posted March 25, 2017 Well, there isn't much more to the script than I already posted. I call the function with ESC key like this: HotKeySet("{Esc}", "_Exit") And it does work. It creates an MsgBox. Some fault is in the function itself. Link to comment Share on other sites More sharing options...
water Posted March 25, 2017 Share Posted March 25, 2017 (edited) 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 March 25, 2017 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
supraspecies Posted March 25, 2017 Author Share Posted March 25, 2017 (edited) 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 March 25, 2017 by supraspecies Link to comment Share on other sites More sharing options...
water Posted March 25, 2017 Share Posted March 25, 2017 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
supraspecies Posted March 25, 2017 Author Share Posted March 25, 2017 Thank you for your help, I got it working. Link to comment Share on other sites More sharing options...
water Posted March 25, 2017 Share Posted March 25, 2017 My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now