Funktionreferenz


_WinAPI_RegisterHotKey


Defines a system-wide hot key

#include <WinAPISys.au3>
_WinAPI_RegisterHotKey ( $hWnd, $iID, $iModifiers, $vKey )

Parameter

$hWnd Handle to the window that will receive WM_HOTKEY messages generated by the hot key. If this parameter
is 0, WM_HOTKEY messages are posted to the message queue of the calling thread and must be processed in
the message loop.
$iID Specifies the identifier of the hot key. An application must specify an id value in the range
0x0000 through 0xBFFF.
$iModifiers Specifies keys that must be pressed in combination with the key specified by the $vKey parameter
in order to generate the WM_HOTKEY message.
The $iModifiers parameter can be a combination of the following values.
    $MOD_ALT
    $MOD_CONTROL
    $MOD_SHIFT
    $MOD_WIN

Windows 7 or later
    $MOD_NOREPEAT
$vKey Specifies the virtual-key code of the hot key ($VK_*).

Rückgabewert

Success: True.
Failure: False, call _WinAPI_GetLastError() to get extended error information.

Bemerkungen

When a key is pressed, the system looks for a match against all hot keys. Upon finding a match, the system posts
the WM_HOTKEY message to the message queue of the window with which the hot key is associated. If the hot key is
not associated with a window, then the WM_HOTKEY message is posted to the thread associated with the hot key.

_WinAPI_RegisterHotKey() fails if the keystrokes specified for the hot key have already been registered by
another hot key.

In Windows XP, if a hot key already exists with the same $hWnd and $iID parameters,
it is replaced by the new hot key.

In Windows Vista and subsequent versions of Windows, if a hot key already exists with the same $hWnd and $iID
parameters, it is maintained along with the new hot key. In these versions of Windows, the application must
explicitly call _WinAPI_UnregisterHotKey() to unregister the old hot key.

Verwandte Funktionen

_WinAPI_UnregisterHotKey

Siehe auch

Suche nach RegisterHotKey in der MSDN Bibliothek.

Beispiel

#include <APISysConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIConv.au3>
#include <WinAPISys.au3>
#include <WindowsConstants.au3>

Opt('TrayAutoPause', 0)

OnAutoItExitRegister('OnAutoItExit')

Local $hWnd = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'))
GUIRegisterMsg($WM_HOTKEY, 'WM_HOTKEY')

; Setzt ALT-D
_WinAPI_RegisterHotKey($hWnd, 0x0144, $MOD_ALT, 0x44)
; Setzt ESC
_WinAPI_RegisterHotKey($hWnd, 0x011B, 0, 0x1B)

While 1
    Sleep(1000)
WEnd

Func WM_HOTKEY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam

    Switch _WinAPI_HiWord($lParam)
        Case 0x44
            MsgBox($MB_SYSTEMMODAL, '', 'Es wurde ALT-D gedrückt')
        Case 0x1B
            MsgBox($MB_SYSTEMMODAL, '', 'Es wurde ESC gedrückt')
            Exit
    EndSwitch
EndFunc   ;==>WM_HOTKEY

Func OnAutoItExit()
    _WinAPI_UnregisterHotKey($hWnd, 0x0144)
    _WinAPI_UnregisterHotKey($hWnd, 0x011B)
EndFunc   ;==>OnAutoItExit