I don't really know how to check what hotsetkey returns.
I mean, hotsetkey works, its role is to say :F1 now runs this function.
And not : If you press F1, I'll run this function.
So indeed, if I set :
if HotKeySet("{F1}", "FocusProg") Then
MsgBox(0, "Ok !", "Works...")
Else
MsgBox(0, "... !", "Doesn't work...")
EndIf
Once the gui appears, I'm spammed of "Works..." Msgbox (my hotsetkey function is in a while loop).
I suppose I havn't understood what you exactly meant.
@KaFu : I don't understand how to use it, even with an exemple. I guess I'm not skilled enough to use hooks.
But I'm pretty sure that it is what I need, so I can detect "F1 key is pressed" at any time.
Edit : I've managed to adapt an exemple I found in the help file. I guess it needs some more modifications.
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)
Global $hHook, $hStub_KeyProc, $buffer = ""
_Main()
Func _Main()
OnAutoItExitRegister("Cleanup")
Local $hmod
$hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
$hmod = _WinAPI_GetModuleHandle(0)
$hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod)
While 1
Sleep(10)
WEnd
EndFunc
Func EvaluateKey($keycode)
If ($keycode = 112) then ;F1
$buffer &= Chr($keycode)
Send("TEST")
Else
$buffer = ""
EndIf
EndFunc
;===========================================================
; callback function
;===========================================================
Func _KeyProc($nCode, $wParam, $lParam)
Local $tKEYHOOKS
$tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
If $nCode < 0 Then
Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndIf
If $wParam = $WM_KEYDOWN Then
EvaluateKey(DllStructGetData($tKEYHOOKS, "vkCode"))
EndIf
Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam)
EndFunc
Func Cleanup()
_WinAPI_UnhookWindowsHookEx($hHook)
DllCallbackFree($hStub_KeyProc)
EndFunc