In Windows on some keyboard layouts ALTR_GR sends LCTRL + ALT, you need a trick to differentiate between a real LCTRL and a fake one.
Extracted from my SGL library to show a way to do it:
Code: Select all
Procedure ios_TranslateKey (*WinMsg.MSG, *KeyCode.Integer, *ScanCode.Integer)
; Process the keyboard messages and set some specific return values to differentiate between specific keys positions.
; Also trap the special case of the ALT_GR key present on some keyboard layouts.
Protected wParam = *WinMsg\wParam
Protected lParam = *WinMsg\lParam
Protected NextMSG.MSG, TimeStamp
*ScanCode\i = (lParam >> 16) & $ff ; bits 16->23
Select wParam
Case #VK_SHIFT ; check if it's a left shift or a right shift
If *ScanCode\i = $2A
*KeyCode\i = #VK_LSHIFT
Else ; $36
*KeyCode\i = #VK_RSHIFT
EndIf
Case #VK_CONTROL ; check if it's a left control or a right control
; is this an extended key (right key) ?
If lParam & 1<<24
*KeyCode\i = #VK_RCONTROL
Else
*KeyCode\i = #VK_LCONTROL
; ALTR_GR sends LCTRL, then ALT so we check if this #sgl_Key_LEFT_CONTROL is legitimate
TimeStamp = GetMessageTime_()
; take a look to the next message in the queue
If PeekMessage_(@NextMSG, *WinMsg\hWnd, 0, 0, #PM_NOREMOVE)
If NextMSG\message = #WM_KEYDOWN Or NextMSG\message = #WM_SYSKEYDOWN Or NextMSG\message = #WM_KEYUP Or NextMSG\message = #WM_SYSKEYUP
If NextMSG\wParam = #VK_MENU ; ALT
If NextMSG\time = TimeStamp ; generated at the same time, this is the giveaway !
*KeyCode\i = 0 ; it was a fake one, discard the #sgl_Key_LEFT_CONTROL
*ScanCode\i = 0 ; and the associated scancode
EndIf
EndIf
EndIf
EndIf
EndIf
Case #VK_MENU ; check if it's a left alt or a right alt
; is this an extended key (right key) ?
If lParam & 1<<24
*KeyCode\i = #VK_RMENU
Else
*KeyCode\i = #VK_LMENU
EndIf
Case #VK_RETURN ; check if it's a normal return or a keypad return
; is this an extended key (right key) ?
If lParam & 1<<24
*KeyCode\i = #VK_NONAME ; keypad return
Else
*KeyCode\i = #VK_RETURN
EndIf
Default
*KeyCode\i = wParam
EndSelect
EndProcedure
In general on Windows it's a lot better to avoid using the ALT keys especially in windowed programs, since for example the left ALT has a special meaning (invokes the menu).
You can try to see if KeyboardMode() changes something, I never use PB keyboard library so I've no idea.