Skip to content

Fix AltGr key being detected as Ctrl key on German keyboards #2

@JC2k8

Description

@JC2k8

On German keyboards the Alt Gr key is needed to produce round or curly brackets in combination with the keys 7 to 0. While it technically still works, the current implementation also switches tabs if you have the appropriate number of tabs open. The Alt Gr key is equivalent to pressing both Ctrl and Alt at the same time.

I downloaded the project, changed all the EOL characters from vbLf to vbCrLf, and built all the DLLs. In order to fix the problem I created a new function in MDIMonitor.bas in the CHTabMDI project:

'new function to make things easier
Private Function KeyPressed(ByVal Key As Long) As Boolean
  KeyPressed = CBool((GetAsyncKeyState(Key) And &H8000) = &H8000)
End Function

Afterwards, I simply enhanced the CtrlDown detection by also querying the state of the Alt key:

' This is where we ctrl-switch tabs
Private Sub ICHPlugin_OnKeyHook(bHandled As Boolean, lReturn As Long, wParam As Long, lParam As Long)
    ' Call into VBWinApi to get the control key state
    
'    CtrlDown = GetAsyncKeyState(vbKeyControl)
    'Fix AltGr-Key on German keyboard layout so that only the ctrl keys enable switching tabs
    CtrlDown = KeyPressed(vbKeyControl) And Not KeyPressed(vbKeyMenu)

    If m_CtrlPressed Then
        Select Case wParam
            Case vbKey0 To vbKey9
                Call m_tabManager.ShortcutActivate(wParam)
            
            Case vbKeyReturn
                Call MaximizeCodePane
                
        End Select
    End If
End Sub

Whether you implement the change or not, this way it's documented and easy to fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions