qwert Posted December 1, 2010 Share Posted December 1, 2010 I have a script that displays intermediate results to the user and awaits their response to either Continue or to Go Back one step in the procedure that's in progress. My script calls a custom Wait function that loops until the user responds. So far, I've only been able to set up my Wait function for either the mouse clicks (using Do Until GUIGetMsg) or the Left and Right Arrows (using HotKeySet). What I haven't figured out is how to have the same Wait function cover both types of user actions. IOW, how can the function be constructed to pause the script until one of four possible user actions are entered:Right Mouse Click = Go BackLeft Mouse Click = ContinueRight Arrow Key = ContinueLeft Arrow Key = Go BackAll other keys and actions should be ignored except for ESC, which terminates the script. (The Wait function returns a "Back" or "Continue" indicator, of course.) I've looked at dozens of examples on these forums, but all the ones I've found use either the keystroke method or the mouse method, but not both.Any suggestions will be appreciated. Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 1, 2010 Share Posted December 1, 2010 It's easier to handle the GUI events the same as the hot keys: #include <GuiConstantsEx.au3> Opt("GuiOnEventMode", 1) HotKeySet("{RIGHT}", "_Continue") HotKeySet("{LEFT}", "_GoBack") HotKeySet("{ESC}", "_Quit") Global $iMsg = 0 Global $hGUI = GUICreate("Test") GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit") GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_Continue") GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "_GoBack") GUISetState() While 1 Sleep(10) WEnd Func _Continue() $iMsg += 1 ToolTip($iMsg & ": Continuing...") EndFunc ;==>_Continue Func _GoBack() $iMsg += 1 ToolTip($iMsg & ": Going back...") EndFunc ;==>_GoBack Func _Quit() Exit EndFunc ;==>_Quit 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 Link to comment Share on other sites More sharing options...
iamtheky Posted December 1, 2010 Share Posted December 1, 2010 #Include <Misc.au3> while 1 If _ispressed("02") or _ispressed("25") Then msgbox (0, '' , "Go Back", 5) Endif If _ispressed("01") or _ispressed("27") Then msgbox (0, '' , "Continue", 5) Endif wend ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 1, 2010 Share Posted December 1, 2010 The problem is that _IsPressed() and HotKeySet() will both react when you are not on the target GUI. This is even better, as all the action is restricted to the appropriate GUI: #include <GuiConstantsEx.au3> Opt("GuiOnEventMode", 1) Global $iMsg = 0, $aAccel[2][2] = [["{LEFT}", 0],["{RIGHT}", 0]] Global $hGUI = GUICreate("Test", 300, 300) GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit") GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_Continue") GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "_GoBack") $aAccel[1][1] = GUICtrlCreateButton("CONTINUE", 40, 250, 90, 30) GUICtrlSetOnEvent(-1, "_Continue") $aAccel[0][1] = GUICtrlCreateButton("GO BACK", 170, 250, 90, 30) GUICtrlSetOnEvent(-1, "_GoBack") GUISetAccelerators($aAccel, $hGUI) GUISetState() While 1 Sleep(10) WEnd Func _Continue() $iMsg += 1 ToolTip($iMsg & ": Continuing...") EndFunc ;==>_Continue Func _GoBack() $iMsg += 1 ToolTip($iMsg & ": Going back...") EndFunc ;==>_GoBack Func _Quit() Exit EndFunc ;==>_Quit 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 Link to comment Share on other sites More sharing options...
qwert Posted December 1, 2010 Author Share Posted December 1, 2010 Thanks very much. Either method will work for my specific application because it runs as the topmost window. But the accelerator table method looks very appropriate for other apps. I haven't had a reason to investigate it before. In fact, I'm not sure I fully understand the concept. I found this short explanation in a book on cross-platform widgets:An accelerator implements a keyboard shortcut for a menu command, enabling the user to execute the command quickly. These shortcuts take precedence over other keyboard processing.Does that do it justice? Other than restricting to the specific GUI, are there other advantages? I couldn't find much in the AutoIt Help, so I'm thinking it's not used often. Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 1, 2010 Share Posted December 1, 2010 The accelerator is a GUI-specific hot key. When you hit that hot key it is seen by the GUI as though you clicked an associated control. In the demo I posted the {LEFT} and {RIGHT} hot keys were associated with the GoBack and Continue button control IDs. Hitting the hot keys is seen by the GUI as the same thing as clicking the button. The only thing remotely tricky about it is the need to use a 2D array to set up the accelerators. 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 Link to comment Share on other sites More sharing options...
qwert Posted December 2, 2010 Author Share Posted December 2, 2010 That's good to know. Just for reference, here's the resulting function ... using the simpler _IsPressed method: #Include <Misc.au3> Func Wait() While 1 If _ispressed("02") or _ispressed("25") Then Return "Go Back" Endif If _ispressed("01") or _ispressed("27") Then Return "Continue" Endif Wend EndFunc Thanks for your help. 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