Allow User To Entering Number in The Same Time

Preparation :
Add 5 Labels to your form.

Form Code
'currectKeys array holds all the currently pressed keys.
'For example, if Space Bar is the only pressed key, currentKeys(32) value will
'be True (because Space Bar keyCode is 32) and all the others array's values will
'be False.
Dim currentKeys(0 To 250) As Boolean

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'Pressing a key and holding it down, will launch the KeyDown event over
'and over again. so we check if the user just pressed the key, or the key
'is already down.
If currentKeys(KeyCode) = False Then
'Update the array that the current key has been pressed.
currentKeys(KeyCode) = True
If KeyCode = vbKeyLeft Then Label1 = "Left"
If KeyCode = vbKeyRight Then Label2 = "Right"
If KeyCode = vbKeyUp Then Label3 = "Up"
If KeyCode = vbKeyDown Then Label4 = "Down"
If KeyCode = vbKeySpace Then Label5 = "Fire"
End If
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
'Update the array that the current key is no longer being pressed.
currentKeys(KeyCode) = False
If KeyCode = vbKeyLeft Then Label1 = ""
If KeyCode = vbKeyRight Then Label2 = ""
If KeyCode = vbKeyUp Then Label3 = ""
If KeyCode = vbKeyDown Then Label4 = ""
If KeyCode = vbKeySpace Then Label5 = ""
End Sub

Private Sub Form_Load()
'Initialize labels text
Label1 = ""
Label2 = ""
Label3 = ""
Label4 = ""
Label5 = ""
End Sub

No comments: