Key Board Events in VB

Key Board Events

Source Code and Screen Design


Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 38 Then
MsgBox ("The UP Arrow was Pressed")
End If
End Sub



Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 40 Then
MsgBox ("The DOWN Arrow was Pressed")
ElseIf KeyCode = 37 Then
MsgBox ("The LEFT Arrow was Pressed")
ElseIf KeyCode = 39 Then
MsgBox ("The RIGHT Arrow was Pressed")
End If
End Sub







Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text1.SetFocus
End If
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)

Dim Mychar As String
Mychar = Text1.Text
Text1.Text = Mychar

MsgBox "You Have Pressed " & Mychar & Asc(Mychar)
Text1.Text = ""

End Sub