Phenom Posted June 11, 2010 Share Posted June 11, 2010 (edited) Can GUI controls act as hotkeys? Edited June 11, 2010 by Phenom Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 11, 2010 Moderators Share Posted June 11, 2010 (edited) Phenom,A HotKey will (in almost all circumstances) interrupt whatever the script is doing to run the code associated with it.How a GUI control reacts depends on the mode you use:- OnEvent mode: The control acts like a HotKey and interrupts the current function: #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) $hGUI = GUICreate("Test", 500, 500) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") $hButton = GUICtrlCreateButton("Interrupt", 10, 10, 80, 30) GUICtrlSetOnEvent($hButton, "_On_Interrupt") GUISetState() _Long_Function() ; Start a long function ; Enter an infinite loop While 1 Sleep(10) WEnd Func _Long_Function() $iBegin = TimerInit() While TimerDiff($iBegin) < 100000 ConsoleWrite(@SEC & @CRLF) Sleep(1000) WEnd EndFunc Func _On_Interrupt() MsgBox(0, "Hi", "Interrupted") EndFunc Func CLOSEClicked() Exit EndFunc- GetMessage mode: Control clicks are queued and you cannot break into a running function easily. Does that answer your question? M23Edit: typnig! Edited June 11, 2010 by Melba23 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 Link to comment Share on other sites More sharing options...
picea892 Posted June 12, 2010 Share Posted June 12, 2010 He might mean Guictrlsetaccelerators.... ; A simple custom messagebox that uses the MessageLoop mode #include <GUIConstantsEx.au3> GUICreate("Custom Msgbox", 210, 80) GUICtrlCreateLabel("Please click a button!", 10, 10) $YesID = GUICtrlCreateButton("Yes", 10, 50, 50, 20) $NoID = GUICtrlCreateButton("No", 80, 50, 50, 20) $ExitID = GUICtrlCreateButton("Exit", 150, 50, 50, 20) ; Set accelerators for Ctrl+y and Ctrl+n Dim $AccelKeys[2][2]=[["^y", $YesID], ["^n", $NoID]] GUISetAccelerators($AccelKeys) GUISetState() ; display the GUI Do $msg = GUIGetMsg() Select Case $msg = $YesID MsgBox(0, "You clicked on", "Yes") Case $msg = $NoID MsgBox(0, "You clicked on", "No") Case $msg = $ExitID MsgBox(0, "You clicked on", "Exit") Case $msg = $GUI_EVENT_CLOSE MsgBox(0, "You clicked on", "Close") EndSelect Until $msg = $GUI_EVENT_CLOSE Or $msg = $ExitID Link to comment Share on other sites More sharing options...
Phenom Posted June 14, 2010 Author Share Posted June 14, 2010 OnEvent mode did the trick. Thanks. Link to comment Share on other sites More sharing options...
AndreyS Posted August 28, 2012 Share Posted August 28, 2012 (edited) Hi developers! Tell me, please, why the next small change example, Button does not work and how to make it work? Functions usually start with buttons. I would be very grateful! expandcollapse popup#include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) $hGUI = GUICreate("Test", 500, 500) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") $hButton = GUICtrlCreateButton("Interrupt", 10, 10, 80, 30) GUICtrlSetOnEvent($hButton, "_On_Interrupt") $hButton2 = GUICtrlCreateButton("Interrupt2", 100, 10, 80, 30) GUICtrlSetOnEvent($hButton2, "_Long_Function") GUISetState() ; Enter an infinite loop While 1 Sleep(10) WEnd Func _Long_Function() $iBegin = TimerInit() While TimerDiff($iBegin) < 100000 ConsoleWrite(@SEC & @CRLF) Sleep(1000) WEnd EndFunc Func _On_Interrupt() MsgBox(0, "Hi", "Interrupted") EndFunc Func CLOSEClicked() Exit EndFunc Edited August 28, 2012 by AndreyS Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 28, 2012 Moderators Share Posted August 28, 2012 AndreyS,The Interrupting a running function tutorial in the Wiki will explain all. But do ask again if you still have problems. 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 Link to comment Share on other sites More sharing options...
AndreyS Posted August 30, 2012 Share Posted August 30, 2012 Thank you! This is exactly what I'd had! Not an easy decision, of course, but probably the best in the language Autoit. Tell me more, please, how to recognize / catch pressing the close button (the event $ GUI_EVENT_CLOSE) using the GUIRegisterMsg ($WM_COMMAND, "_WM_COMMAND")? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 30, 2012 Moderators Share Posted August 30, 2012 AndreyS, how to recognize / catch pressing the close button (the event $ GUI_EVENT_CLOSE) using the GUIRegisterMsgTo do that you use the WM_SYCOMMAND message like this: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("Test", 500, 500) GUISetState() GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND") While 1 Sleep(10) WEnd Func _WM_SYSCOMMAND($hWnd, $iMsg, $wParam, $lParam) Switch $wParam Case 0xF060 MsgBox(0, "Hi", "[X] pressed") Exit EndSwitch EndFunc All clear? 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 Link to comment Share on other sites More sharing options...
AndreyS Posted August 31, 2012 Share Posted August 31, 2012 Yes, very grateful! All clear so far! 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