I am working on a keyboard teaching aid similar to mavis beacon. With the following code i am able to detect if the enter key is pressed on the keyboard.

If e.KeyChar = Microsoft.VisualBasic.ChrW(keys.enter) Then
    MsgBox("Enter key is pressed")
End If

but what i want to do is that i want to make the keyword "keys.enter" to become a variable name so that the whole code can be called upon as a subroutine to handle all types of letter being pressed by the user so that i dont have to repeat the whole code for the keys needed. Thanks in advance

Add this foloowing function :

Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
    If msg.WParam.ToInt32() = CInt(Keys.Enter) Then
        Return True
    End If
    Return MyBase.ProcessCmdKey(msg, keyData)
End Function

@Jx Man this code is doing the same thing as what I have done. What i want to do is a single function that can test for when any of the letter A-Z or a-z 0-9 and other keys of the keyboard is pressed the message should alert what has been pressed similar to something like the following code but dont know how to go about it

 Dim chara As Keys
        If e.KeyChar = Microsoft.VisualBasic.ChrW(chara) Then
            MsgBox("Enter key is pressed")
        End If
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
    MsgBox(e.KeyChar & " key is pressed")
End Sub

@Jx Man It worked Thanks.

You're welcome.
Don't forget to mark this thread as solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.