Function Reference


GUISetAccelerators

Sets the accelerator table to be used in a GUI window.

GUISetAccelerators ( accelerators [, winhandle] )

Parameters

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).

Return Value

Success: 1.
Failure: 0.

Remarks

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][2] - where n is the number of Accelerator keys to set:

    $aArray[0][0] = 1st Accelerator key (in HotKeySet() format)
    $aArray[0][1] = Associated ControlID for 1st accelerator, as returned by GUICtrlCreate...
    $aArray[1][0] = 2nd Accelerator key
    $aArray[1][1] = Associated ControlID for 2nd accelerator
    ...
    $aArray[n][0] = nth Accelerator key
    $aArray[n][1] = Associated ControlID for the nth accelerator


Passing this function a non-array parameter will unset all accelerators for the specified winhandle.

Related

GUICreate, HotKeySet

Example

#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[2][2] = [["^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