Code: Select all
EnableExplicit
; Structure KBDLLHOOKSTRUCT
; vkCode.l
; scanCode.l
; flags.l
; time.l
; *dwExtraInfo.Long
; EndStructure
Global hHook
Procedure KeyboardHook(nCode, wParam, *kc.KBDLLHOOKSTRUCT)
Static x
Static c
If nCode = #HC_ACTION
Select *kc\vkCode
Case 160
x | 1
; ProcedureReturn 1 ; return does not transfer the event to the queue, but catches it on itself
Case 164
x | 2
Default
x = 0
EndSelect
If x = 2
c + 1
Debug c
; here I can query the current layout at the moment the keys are pressed
EndIf
EndIf
ProcedureReturn CallNextHookEx_(#Null, nCode, wParam, *kc)
EndProcedure
If OpenWindow(0, 0, 0, 220, 100, "Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
hHook = SetWindowsHookEx_(#WH_KEYBOARD_LL, @KeyboardHook(), #Null, 0)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
UnhookWindowsHookEx_(hHook)
CloseWindow(0)
End
EndSelect
ForEver
EndIf
Code: Select all
#Window = 0
#Timer = 0
Define flgTimer = 200
Define Layout, old_Layout
If OpenWindow(#Window, 0, 0, 220, 100, "Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If flgTimer
AddWindowTimer(#Window, #Timer, flgTimer)
EndIf
Repeat
Select WaitWindowEvent()
Case #PB_Event_Timer
If EventTimer() = #Timer
Layout = GetKeyboardLayout_(GetWindowThreadProcessId_(GetForegroundWindow_(), 0))
If old_Layout <> Layout
old_Layout = Layout
Debug Layout >> 16
EndIf
EndIf
Case #PB_Event_CloseWindow
CloseWindow(#Window)
End
EndSelect
ForEver
EndIf