clayreimann / CodeHelp

An extension framework for Visual Studio 6, initally developed by @luthv
13 stars 11 forks source link

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

Open JC2k8 opened 7 years ago

JC2k8 commented 7 years ago

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.

clayreimann commented 7 years ago

Nice!

If you want to open a PR I'd be happy to merge it.