However I'm not sure it works on Win7 and higher (cannot test now), on XP x86 works fine.
Code: Select all
EnableExplicit
; set some WinAPI constants which PB misses
#KF_EXTENDED = $100
#LLKHF_EXTENDED = (#KF_EXTENDED >> 8)
; procedure to receive hook messages
Procedure KeyMsg (msg.l, WPARAM.l, LPARAM.l)
If (WPARAM = #WM_KEYDOWN Or WPARAM = #WM_SYSKEYDOWN)
Protected *st_hook.KBDLLHOOKSTRUCT = LPARAM
Protected sc = *st_hook\scanCode
Protected vk = *st_hook\vkCode
Debug "IsExtended: " + Str(*st_hook\flags) ; that str(flags) seems not rignt, but generally works
Debug "ScanCode: " + sc
Debug "VirtualKey: " + vk
Debug "------"
; If vk = #VK_ESCAPE ;
;
; EndIf
EndIf
EndProcedure
;;;;;;;;;;;;;;;;;;;;;;;;;;
Define KeyboardHook = SetWindowsHookEx_(#WH_KEYBOARD_LL, @KeyMsg(), GetModuleHandle_(#Null), 0)
OpenWindow(1, 1, 1, 1, 1, "Global keyboard hook test") ; need to have some window, else you cannot receive windows messages
Debug "Press any key in any window..."
Repeat
If WaitWindowEvent(16) = #PB_Event_CloseWindow
Break
EndIf
ForEver
UnhookWindowsHookEx_(KeyboardHook)