I saw some old posts where people complained that HotKeySet() doesn't work for some keys like F13 - F24. I made some tests and I end up with this.
#include-once
Global $__dummy_win, $__mHotkeys[]
Func HotKeyInit()
$__dummy_win = GUICreate('', 0, 0, 0, 0, 0x80000000)
GUISetState(@SW_SHOW, $__dummy_win)
GUIRegisterMsg(0x0312, 'WM_HOTKEY')
EndFunc
Func HotKeyUnInit()
GUIRegisterMsg(0x0312, '')
GUIDelete($__dummy_win)
EndFunc
Func HotKeySetEx($vkCode, $sFunction)
Local $aCall, $aHotkey[2]
Local Static $iID = 0
$iID += 1
$aCall = DllCall('user32.dll', 'bool', 'RegisterHotKey', 'hwnd', $__dummy_win, 'int', $iID, 'uint', 0x4000, 'uint', $vkCode)
If $aCall[0] <> 0 Then
$aHotkey[0] = $iID
$aHotkey[1] = $sFunction
$__mHotkeys[$vkCode] = $aHotkey
EndIf
Return $aCall[0]
EndFunc
Func HotKeyUnset($vkCode)
Local $iID = ($__mHotkeys[$vkCode])[0]
Local $aCall = DllCall('user32.dll', 'bool', 'UnregisterHotKey', 'hwnd', $__dummy_win, 'int', $iID)
If $aCall[0] <> 0 Then MapRemove($__mHotkeys, $vkCode)
Return $aCall[0]
EndFunc
Func WM_HOTKEY($hWnd, $iMsg, $wParam, $lParam)
Local $vkCode = BitShift($lParam, 16)
If MapExists($__mHotkeys, $vkCode) Then
Local $aHotkey = $__mHotkeys[$vkCode]
Call($aHotkey[1])
EndIf
Return 'GUI_RUNDEFMSG'
EndFunc
And here is a basic example:
#include <HotKeySetEx.au3>
Global Const $F13 = 0x7C
HotKeyInit()
HotKeySetEx($F13, 'Test')
; Simulate F13
DllCall('user32.dll', 'none', 'keybd_event', 'byte', $F13, 'byte', 0x64, 'dword', 0, 'ulong_ptr', 0)
While True
Sleep(10)
WEnd
HotKeyUnset($F13)
HotKeyUnInit()
Func Test()
MsgBox(0, '', 'Test')
Exit
EndFunc
I am not aware about native HotKeySet() implementation but I wonder if it's a trivial task to add these extended function keys so it won't be necessary to register them in that way. Some might argue that keyboards now don't use these keys anymore, but it's not true at all. There are some new keyboard having these physical keys (picture below), but they are rare indeed.
Edit: after a quick look over an older version of AutoIt source code it seems trivial to allow these function keys to be used as hotkeys. However, I'm not sure how much HotKeySet() has been changed in the newer versions of AutoIt.