LeftControl = RightAlt?

Everything related to 3D programming
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

LeftControl = RightAlt?

Post 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
Image
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: LeftControl = RightAlt?

Post by Thunder93 »

Works correctly here...
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: LeftControl = RightAlt?

Post 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?
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: LeftControl = RightAlt?

Post 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..
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: LeftControl = RightAlt?

Post by Thunder93 »

What version of PB you guys using when experiencing problems?
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: LeftControl = RightAlt?

Post by DK_PETER »

Me:
Windows 7 Ultimate 64bit
PB 5.22 LTS B2 (X64)
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: LeftControl = RightAlt?

Post by Thunder93 »

Thanks. I did test both codes on PB 5.22 LTS B2 (x64 & x86). Is correctly working for me.
Last edited by Thunder93 on Sun Mar 16, 2014 9:33 pm, edited 1 time in total.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: LeftControl = RightAlt?

Post 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
DE AA EB
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: LeftControl = RightAlt?

Post 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
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: LeftControl = RightAlt?

Post 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.
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Re: LeftControl = RightAlt?

Post 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.
Image
Post Reply