JeffL Posted October 26, 2010 Posted October 26, 2010 (edited) I am unsure what the other "blocking functions" are, but I am not calling MsgBox or OpenFilewhatever at the time I am using the hotkeys. Here is some sample code, it will not compile but gives you an idea of what I'm doing: expandcollapse popupglobal $_paused HotKeySet("{PAUSE}", "togglePause") HotKeySet("{ESC}", "exitScript") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _ExitScript() Case $GUI_EVENT_PRIMARYDOWN $aMouseInfo = GUIGetCursorInfo($hChildGUI) if (@error = 0) AND ($aMouseInfo[4] <> 0) AND StringinStr($sNoClickList,"|" & $aMouseInfo[4] & "|") = 0 then if $hFocusedCell <> "" then GUICtrlSetBkColor($hFocusedCell,0xFFFFFF) GUICtrlSetData($hFocusedCell,GUICtrlRead($hEdit)) ;endif $hFocusedCell = "" GUICtrlSetData ($hEdit,"") endif ;if (@error = 0) AND ($aMouseInfo[4] <> 0) then $hFocusedCell = $aMouseInfo[4] GUICtrlSetBkColor($aMouseInfo[4],0x00CCFF) GUICtrlSetData($hEdit,GUICtrlRead($hFocusedCell)) endif Case $hFileExit _ExitScript() Case $hFileOpen _UpdateSplash($hStatus,"Please open spreadsheet") $oSheetData = _OpenExcel(1) if $oSheetData <> 0 then _CreateArray($oSheetData) ;should fill out array here _DrawChildGUI(_Min(UBound($xlsArray,2) - 1,40),UBound($xlsArray,1) - 1) ;i should possibly pass array instead of size of array endif Case $hFilePref _DrawPrefGUI() Case $hRunButton if _ValidateHeaders() then _JavaAttachAndWait("Oracle Applications - ") global $_winPos = _OracleOpen("Purchasing Buyer","Purchase Order Summary") _ProcessPOs() _UpdateSplash($hStatus,"End of spreadsheet reached") endif EndSwitch if _IsPressed("25",$hUser32Dll) AND $hFocusedCell <> "" AND BitAnd(WinGetState("hChildGUI"),8) then _SelectCell(0,-1);LEFTARROW if _IsPressed("26",$hUser32Dll) AND $hFocusedCell <> "" AND BitAnd(WinGetState("hChildGUI"),8) then _SelectCell(-1,0) ;UPARROW if _IsPressed("27",$hUser32Dll) AND $hFocusedCell <> "" AND BitAnd(WinGetState("hChildGUI"),8) then _SelectCell(0,1) ;RIGHTARROW if _IsPressed("28",$hUser32Dll) AND $hFocusedCell <> "" AND BitAnd(WinGetState("hChildGUI"),8) then _SelectCell(1,0) ;DOWNARROW if _IsPressed("0D",$hUser32Dll) AND $hFocusedCell <> "" then _SelectCell(1,0,1) ;ENTER if _IsPressed("09",$hUser32Dll) AND $hFocusedCell <> "" then _SelectCell(0,1,1) ;TAB WEnd func _ExitScript() if isObj($oExcel) then $oExcel.DisplayAlerts = True $oExcel.Quit endif DllClose($hUser32Dll) exit endfunc func _TogglePause() $_paused = NOT $_paused while $_paused sleep(100) wend endfunc i realize this may not be enough to troubleshoot, but basically the hotkeys work while in the GUI loop, but not once i press Run Script button. The functions called in that section do not utilize anything out of the ordinary that didn't prevent me from being able to pause in previous scripts. I can show you the functiosn it calls, but it is basically just a series of java access bridge functions and sends and whatnot. stuff that previously i was able to interrupt when I did not stick it in a GUI. Any idea whats going on? Thanks! Edited October 26, 2010 by JeffL
JohnOne Posted October 26, 2010 Posted October 26, 2010 Try putting a Sleep(10) somewhere in your gui loop. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
jeffml Posted October 26, 2010 Posted October 26, 2010 Hi, I have done more research, as I probably should have before, and it appears it is anytime it answers a GUI message via GUIGetMsg() that it ceases to accept Hotkeys. If I try and execute the hotkeys before triggering one of the GUI events, it works. But once I have triggered a GUI event, it ceases to work. Here is a simplified version of what doesn't work that should compile. Thanks expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> global $_paused = 0 global $iH_MainSize, $iV_MainSize, $iH_MainPos, $iV_MainPos global $hFileMenu, $hViewMenu global $hMainGUI, $hChildGUI $iH_MainSize = 800 $iV_MainSize = 600 $iH_MainPos = 50 $iV_MainPos = 20 HotKeySet("{PAUSE}", "togglePause") HotKeySet("{ESC}", "exitScript") $hMainGUI = GUICreate("test", $iH_MainSize, $iV_MainSize, $iH_MainPos, $iV_MainPos) $hFileMenu = GUICtrlCreateMenu("File") $hFileExit = GUICtrlCreateMenuItem("Exit", $hFileMenu) $hRunButton = GUICtrlCreateButton("Run Script",600, 3, 150, 22) GUISetState(@SW_SHOW, $hMainGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _ExitScript() Case $GUI_EVENT_PRIMARYDOWN Case $hFileExit _ExitScript() Case $hRunButton while 1 sleep(100) wend EndSwitch WEnd func _ExitScript() exit endfunc func _TogglePause() $_paused = NOT $_paused while $_paused sleep(100) wend endfunc So if you press ESC or PAUSE after loading the GUI (while in the GUI loop), it works. Once you you press the Run Script button, the hotkeys no longer work. I hope this is now simple enough for someone to be able to answer. Thanks!
PsaltyDS Posted October 26, 2010 Posted October 26, 2010 (edited) Well, you typo'd your function names, but with that corrected: HotKeySet("{PAUSE}", "_TogglePause") HotKeySet("{ESC}", "_ExitScript") What did you expect it to do? Both the "{PAUSE}" and "{ESC}" hot keys work fine. You can't tell with the "{PAUSE}" function because there isn't anything being done to see paused or not. Once you hit the "Run Script" button, no more GUIGetMsg() processing happens because it's trapped in a While/WEnd loop with no exit. But the hot keys still work even then. Edited October 26, 2010 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Moderators Melba23 Posted October 26, 2010 Moderators Posted October 26, 2010 jeffml,As explained in the Interrupting a running function tutorial in the Wiki, HotKeys are one of the few ways to break into a running function, so I am more than a little surprised that you say they do not work. If I change the HotKey declarations to match the actual function names, the HotKeys work with out problem - as this script with a few added MsgBoxes should show (it works fine for me): expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $_paused = 0 Global $iH_MainSize, $iV_MainSize, $iH_MainPos, $iV_MainPos Global $hFileMenu, $hViewMenu Global $hMainGUI, $hChildGUI $iH_MainSize = 800 $iV_MainSize = 600 $iH_MainPos = 50 $iV_MainPos = 20 HotKeySet("{PAUSE}", "_togglePause") HotKeySet("{ESC}", "_exitScript") $hMainGUI = GUICreate("test", $iH_MainSize, $iV_MainSize, $iH_MainPos, $iV_MainPos) $hFileMenu = GUICtrlCreateMenu("File") $hFileExit = GUICtrlCreateMenuItem("Exit", $hFileMenu) $hRunButton = GUICtrlCreateButton("Run Script", 600, 3, 150, 22) GUISetState(@SW_SHOW, $hMainGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _ExitScript() Case $GUI_EVENT_PRIMARYDOWN Case $hFileExit _ExitScript() Case $hRunButton MsgBox(0, "", "Running!") While 1 Sleep(100) WEnd EndSwitch WEnd Func _ExitScript() Exit EndFunc ;==>_ExitScript Func _TogglePause() $_paused = Not $_paused If $_paused Then MsgBox(0, "", "Paused!") Else MsgBox(0, "", "Not Paused!") EndIf While $_paused Sleep(100) WEnd EndFunc ;==>_TogglePauseOf course, as explained in the tutorial, none of the other GUI controls (such as the [X]) will work. Do you still have the same problem when running this script? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
jeffml Posted October 26, 2010 Posted October 26, 2010 OMG! I am so sorry for wasting anyone's time I just realized what it was. i renamed the exitScript and togglePause functions to _ExitScript and _TogglePause, but didnt change that in the hotkey commands. I cannot believe I made such an oversight, I'm sorry!
jeffml Posted October 26, 2010 Posted October 26, 2010 Well, you typo'd your function names, but with that corrected: HotKeySet("{PAUSE}", "_TogglePause") HotKeySet("{ESC}", "_ExitScript") What did you expect it to do? Both the "{PAUSE}" and "{ESC}" hot keys work fine. You can't tell with the "{PAUSE}" function because there isn't anything being done to see paused or not. Once you hit the "Run Script" button, no more GUIGetMsg() processing happens because it's trapped in a While/WEnd loop with no exit. But the hot keys still work even then. Haha, yes thank you. I just realized that myself.
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