Page 1 of 1
LeftControl = RightAlt?
Posted: Sun Mar 16, 2014 6:07 pm
by Bananenfreak
Heyho,
I don´t know where to put this code (I´m not sure if it´s a bug or not), so could you test this please, before I post another Non-Bug in the bugsection.
Run this code and push Right Alt on your Keyboard (Not Left Control). My PC debugs "Yeah"...
Code: Select all
;Push RIGHT ALT
EnableExplicit
Define.i window
InitSprite()
InitKeyboard()
window = OpenWindow(#PB_Any, 100, 100, 500, 500, "Test")
OpenWindowedScreen(WindowID(window), 0, 0, 500, 500)
Repeat
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_LeftControl)
Debug "Yeah"
EndIf
EndIf
Until WindowEvent() = #PB_Event_CloseWindow
End
Re: LeftControl = RightAlt?
Posted: Sun Mar 16, 2014 6:11 pm
by Thunder93
Works correctly here...
Re: LeftControl = RightAlt?
Posted: Sun Mar 16, 2014 6:14 pm
by Thunder93
Does it happen to just the left control key? Or same experiences if you monitor the left alt and you press the right alt?
Re: LeftControl = RightAlt?
Posted: Sun Mar 16, 2014 6:22 pm
by DK_PETER
This code:
Code: Select all
Define.i window
InitSprite()
InitKeyboard()
window = OpenWindow(#PB_Any, 100, 100, 500, 500, "Test")
OpenWindowedScreen(WindowID(window), 0, 0, 500, 500)
Repeat
ExamineKeyboard()
If KeyboardReleased(#PB_Key_LeftAlt)
Debug "Left Alt"
EndIf
If KeyboardReleased(#PB_Key_LeftControl)
Debug "Left Control"
EndIf
If KeyboardReleased(#PB_Key_RightAlt)
Debug "Right Alt"
EndIf
If KeyboardReleased(#PB_Key_RightControl)
Debug "Right Control"
EndIf
Until WindowEvent() = #PB_Event_CloseWindow
End
Returns, (when pressing right alt key):
Left Control +
Right Alt
I don't know why..
Re: LeftControl = RightAlt?
Posted: Sun Mar 16, 2014 6:27 pm
by Thunder93
What version of PB you guys using when experiencing problems?
Re: LeftControl = RightAlt?
Posted: Sun Mar 16, 2014 6:34 pm
by DK_PETER
Me:
Windows 7 Ultimate 64bit
PB 5.22 LTS B2 (X64)
Re: LeftControl = RightAlt?
Posted: Sun Mar 16, 2014 6:43 pm
by Thunder93
Thanks. I did test both codes on PB 5.22 LTS B2 (x64 & x86). Is correctly working for me.
Re: LeftControl = RightAlt?
Posted: Sun Mar 16, 2014 8:42 pm
by davido
I get 'Yeah' with the following combinations, only:
Left-Control
Left-AltGr
Right-Control
Right-AltGr
PureBasic 5.22 Beta 2 64bit - Windows 7-64bit
Re: LeftControl = RightAlt?
Posted: Sun Mar 16, 2014 11:53 pm
by Demivec
I get nothing when pressing Right-Alt and 'Yeah' only with pressing Left-Control.
PureBasic 5.22 Beta 2 64bit & Windows 8.1 64bit
Re: LeftControl = RightAlt?
Posted: Mon Mar 17, 2014 12:06 am
by luis
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.
Re: LeftControl = RightAlt?
Posted: Mon Mar 17, 2014 2:21 pm
by Bananenfreak
Thank you for your posts, guys.
@luis:
Interesting. Thank you for this piece of code.
So, this is no bug. Good to know.