keyboard input with ctrl,alt, shift + key

5.2k views Asked by At

I am coding some keyboard inputs to my code, but i'm having trouble figuring out how to get the keys that require a ctrl, alt or shift input as well. I tried this but this just make the key work as soon as i press the alt key. I am trying to use the + button that is not on the numpad.

Case Keys.ShiftKey And Keys.Oemplus
            BTB_plus.PerformClick()

And Using keys.Shift does nothing at all

Also, if someone has a list of which key has what name in VB.NET, it would be appreciated. (or good tutorials on this subject)

Would prefer if someone could post the code for a select case statement, thx

2

There are 2 answers

2
AAzami On BEST ANSWER

If you want to use case statement I would then perform this:

Dim bHandled As Boolean = False
    Select Case e.Modifiers
        Case Keys.Control
            If e.KeyCode = Keys.Oemplus Then
                MsgBox("KeyPress CTRL + OEMPLUS")
                e.Handled = True
            End If

            If e.KeyCode = Keys.A Then
                MsgBox("KeyPress CTRL + A")
                e.Handled = True
            End If


        Case Keys.Shift
            If e.KeyCode = Keys.Oemplus Then
                MsgBox("KeyPress Shift + OEMPLUS")
                e.Handled = True
            End If

            If e.KeyCode = Keys.A Then
                MsgBox("KeyPress Shift + A")
                e.Handled = True
            End If

    End Select
1
AAzami On

This should get you there :)

If e.KeyCode = Keys.Oemplus And e.Modifiers = Keys.Control Then
    MsgBox("KeyPress CTRL + OEMPLUS")
    e.Handled = True
End If

http://msdn.microsoft.com/en-us/library/system.windows.forms.keys.aspx