Bert Posted March 6, 2009 Share Posted March 6, 2009 (edited) I have a script I made a few weeks ago to work with a context menu. When I select SFDC, the script will exit. Any other choice works fine. Why would Send("{ESC}") cause the script to close? I think I know the cause. Researching now. Thanks for the help everyone!expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=..\icons\Diary.ico #AutoIt3Wrapper_outfile=Context.exe #AutoIt3Wrapper_UseUpx=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;Opt("TrayIconHide", 1) ;testing Opt("MouseCoordMode", 0) #include <Misc.au3> #include <GUIConstants.au3> #include <WindowsConstants.au3> DIM $ww2, $ww HotKeySet("+!d", "Terminate") $dll = DllOpen("user32.dll") $Form1 = GUICreate("", 100, 22, 193, 80, BitOR($WS_POPUP, $WS_EX_MDICHILD,$WS_EX_TOOLWINDOW)) $List_1 = GUICtrlCreateCombo("", 0, 0, 100, 22) GUICtrlSetData($List_1, "Notepad|Calculator|Word|FireFox|SciTE|SFDC","") WinSetOnTop($Form1, "", 1) GUISetState(@SW_Hide) While 1 $Msg = GUIGetMsg(0) select Case _IsPressed("02", $dll) and _IsPressed("11", $dll) Context() while 2 $Msg2 = GUIGetMsg(0) Select Case $Msg2 = $GUI_EVENT_CLOSE Exit Case _IsPressed("01", $dll) and WinActive($Form1) = 0 GUISetState(@SW_Hide) exitloop Case $Msg2 = $List_1 $G = GUICtrlRead($List_1) If $G = "Notepad" then GUISetState(@SW_HIDE) Run("Notepad.exe") ExitLoop endif If $G = "Calculator" then GUISetState(@SW_HIDE) Run("Calc.exe") ExitLoop endif If $G = "Word" then GUISetState(@SW_HIDE) Run("C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE") ExitLoop endif If $G = "FireFox" then GUISetState(@SW_HIDE) Run("C:\Program Files\Mozilla Firefox\firefox.exe") ExitLoop endif If $G = "SciTE" then GUISetState(@SW_HIDE) Run("C:\Program Files\AutoIt3\SciTE\SciTE.exe") ExitLoop endif If $G = "SFDC" then GUISetState(@SW_HIDE) if WinActive($ww, $ww2) = 0 then WinActivate($ww, $ww2) sleep(300) send("{ESC}") ;This is causing the script to close. Not sure why. ;changed hotsetkey. Made no difference. ExitLoop ;remarking this out made no difference. endif EndSelect WEnd Case $Msg = $GUI_EVENT_CLOSE Exit EndSelect WEnd Func Terminate() Exit 0 EndFunc ;==>Terminate Func Context() $m = MouseGetPos() WinMove($Form1, "", $m[0], $m[1]-22) GUICtrlSetData($List_1, "","") GUICtrlSetData($List_1, "Notepad|Calculator|Word|FireFox|SciTE|SFDC","") $ww2 = WinGetText("[active]") $ww = WinGetTitle("[active]") GUISetState(@SW_SHOW,$Form1) EndFunc ;==>Context Edited March 6, 2009 by Volly The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Bert Posted March 6, 2009 Author Share Posted March 6, 2009 (edited) I tried this: GUISetState(@SW_HIDE) sleep(100) if WinActive($ww, $ww2) = 0 then WinActivate($ww, $ww2) sleep(300) send("dog");THis is causing the script to close. Not sure why. ;changed hotsetkey. Made no difference. $wwQ = WinGetTitle("[active]") $wwQ2 = WinGetText("[active]") MsgBox(0, $wwQ, $wwQ2, 1) ExitLoop;remarking this out made no difference. endif What is odd is MsgBox(0, $wwQ, $wwQ2,1) is reporting nothing. I can wait for the msgbox to close, then no window is active. If I press the esc key, the script closes. Very odd. Edited March 6, 2009 by Volly The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
jvanegmond Posted March 6, 2009 Share Posted March 6, 2009 (edited) Your own window is still active when you send the ESC key. Because WinActivate does not wait until the window is active. It just tells Windows to make the window active. Possible solution is to wait for the window to become active:If $G = "SFDC" then GUISetState(@SW_HIDE) if WinActive($ww, $ww2) = 0 then WinActivate($ww, $ww2) WinWaitActive($ww, $ww2) send("{ESC}") ;This is causing the script to close. Not sure why. ;changed hotsetkey. Made no difference. ExitLoop ;remarking this out made no difference. endifOr as an alternative you may stop your GUI from closing if the ESC key is sent to it by using this option:Opt("GUICloseOnEsc", 0)but that will not fix your problem. Only the symptoms.Can't explain your second symptons though.Edit: Grammar. Edited March 6, 2009 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
Bert Posted March 6, 2009 Author Share Posted March 6, 2009 That works. I will need to do some reading on why my issue is happening in the first place. You gave me some direction to look. Thanks! The Vollatran project My blog: http://www.vollysinterestingshit.com/ 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