Sets the accelerator table to be used in a GUI window.
GUISetAccelerators ( accelerators [, winhandle] )
|accelerators||A 2 dimensional array holding the accelerator table (See remarks).|
|winhandle||[optional] Windows handle as returned by GUICreate() (default is the previously used window).|
Accelerator keys are similar to HotKeys, but there are 2 important differences:
- 1. They are only active when the GUI specified in the function is active which means that, unlike HotKeys, Accelerator keys will not interfere with other running applications.
- 2. They cannot fire a function directly - they action their associated control which then fires the function using GUIGetMsg() or GUICtrlSetOnEvent(). If there is no suitable control available in the GUI then a dummy control can be created using GUICtrlCreateDummy.
The array passed as a parameter to this function contains the Accelerator keys and the ControlIDs of the associated controls. The array must be defined as Local/Global $aArray[n] - where n is the number of Accelerator keys to set:
$aArray = 1st Accelerator key (in HotKeySet() format)
$aArray = Associated ControlID for 1st accelerator, as returned by GUICtrlCreate...
$aArray = 2nd Accelerator key
$aArray = Associated ControlID for 2nd accelerator
$aArray[n] = nth Accelerator key
$aArray[n] = Associated ControlID for the nth accelerator
Passing this function a non-array parameter will unset all accelerators for the specified winhandle.
#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("Custom MsgBox", 225, 80) GUICtrlCreateLabel("Please select a button.", 10, 10) Local $idButton_Yes = GUICtrlCreateButton("Yes", 10, 50, 65, 25) Local $idButton_No = GUICtrlCreateButton("No", 80, 50, 65, 25) Local $idButton_Exit = GUICtrlCreateButton("Exit", 150, 50, 65, 25) ; Set GUIAccelerators for the button controlIDs, these being Ctrl + y and Ctrl + n Local $aAccelKeys = [["^y", $idButton_Yes], ["^n", $idButton_No]] GUISetAccelerators($aAccelKeys) GUISetState(@SW_SHOW) ; Display the GUI. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE MsgBox($MB_SYSTEMMODAL, "You selected", "Close") ExitLoop Case $idButton_Yes MsgBox($MB_SYSTEMMODAL, "You selected", "Yes") ; Displays if the button was selected or the hotkey combination Ctrl + y was pressed. Case $idButton_No MsgBox($MB_SYSTEMMODAL, "You selected", "No") ; Displays if the button was selected or the hotkey combination Ctrl + n was pressed. Case $idButton_Exit MsgBox($MB_SYSTEMMODAL, "You selected", "Exit") ExitLoop EndSwitch WEnd GUIDelete() ; Delete the GUI. EndFunc ;==>Example