'GetKeyboardState API: Returns the current status of the entire keyboard...
'this can include upper ASCII characters for which there is no key,
'and even the three mouse buttons.
Private Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long
'keycode constants... you'll have to lookup the other 250+ on the internet :-)
Const VK_A = &H41 'virtual keycode for A (or a)
Const VK_D = &H44 'virtual keycode for D (or d)
Const VK_S = &H53 'virtual keycode for S (or s)
Const VK_W = &H57 'virtual keycode for W (or w)
Const KeyIsDown = &H80 'bit which indicates key is currently down
'This event occurs when the user presses or releases an ANSI key.
'Keep in mind that function keys, editing keys, navigation keys,
'and any combination of these are not recognized by the KeyPress
'event. Also remember to set the form's KeyPreview property to True.
Private Sub Form_KeyPress(KeyAscii As Integer)
'dimension needed variables
Dim KeyboardState(0 To 255) As Byte 'byte array to hold keyboard status
Dim retval As Long 'return value for GetKeyboardState
'call API
retval = GetKeyboardState(KeyboardState(0))
If retval = 0 Then '0 indicates API call error
MsgBox ("Keyboard Error") 'notify user of error
Exit Sub 'stop processing this keystroke
End If
'process keystroke
If KeyboardState(VK_A) And KeyIsDown Then 'if A is down
If KeyboardState(VK_D) And KeyIsDown Then 'if D is down
Label1.Caption = "AD" ' - or -
ElseIf KeyboardState(VK_S) And KeyIsDown Then 'if S is down
Label1.Caption = "AS" ' - or -
ElseIf KeyboardState(VK_W) And KeyIsDown Then 'if W is down
Label1.Caption = "AW"
Else
Label1.Caption = "A"
End If
ElseIf KeyboardState(VK_D) And KeyIsDown Then 'if D is down
If KeyboardState(VK_A) And KeyIsDown Then
Label1.Caption = "DA"
ElseIf KeyboardState(VK_S) And KeyIsDown Then
Label1.Caption = "DS"
ElseIf KeyboardState(VK_W) And KeyIsDown Then
Label1.Caption = "DW"
Else
Label1.Caption = "D"
End If
ElseIf KeyboardState(VK_S) And KeyIsDown Then 'if S is down
If KeyboardState(VK_A) And KeyIsDown Then
Label1.Caption = "SA"
ElseIf KeyboardState(VK_D) And KeyIsDown Then
Label1.Caption = "SD"
ElseIf KeyboardState(VK_W) And KeyIsDown Then
Label1.Caption = "SW"
Else
Label1.Caption = "S"
End If
ElseIf KeyboardState(VK_W) And KeyIsDown Then 'if W is down
If KeyboardState(VK_A) And KeyIsDown Then
Label1.Caption = "WA"
ElseIf KeyboardState(VK_D) And KeyIsDown Then
Label1.Caption = "WD"
ElseIf KeyboardState(VK_S) And KeyIsDown Then
Label1.Caption = "WS"
Else
Label1.Caption = "W"
End If
End If
End Sub