Imports Microsoft.DirectX
Imports Microsoft.DirectX.DirectInput
Imports Microsoft.DirectX.DirectInput.CooperativeLevelFlags
Public Class Keyboard_Handeler
Public KB As New DirectInput.Device(DirectInput.SystemGuid.Keyboard)
Public KeysPressed(28) As String
Sub New(ByVal OwnerForm)
KB.SetCooperativeLevel(OwnerForm, Background Or NonExclusive)
KB.Acquire()
End Sub
Protected Overrides Sub Finalize()
KB.Dispose()
KB = Nothing
MyBase.Finalize()
End Sub
Public Sub GetKeyboardValues()
Dim State As DirectInput.KeyboardState
State = KB.GetCurrentKeyboardState
'Alphas
If State.Item(Key.A) Then KeysPressed(0) = "a" Else KeysPressed(0) = ""
If State.Item(Key.B) Then KeysPressed(1) = "b" Else KeysPressed(1) = ""
If State.Item(Key.C) Then KeysPressed(2) = "c" Else KeysPressed(2) = ""
If State.Item(Key.D) Then KeysPressed(3) = "d" Else KeysPressed(3) = ""
If State.Item(Key.E) Then KeysPressed(4) = "e" Else KeysPressed(4) = ""
If State.Item(Key.F) Then KeysPressed(5) = "f" Else KeysPressed(5) = ""
If State.Item(Key.G) Then KeysPressed(6) = "g" Else KeysPressed(6) = ""
If State.Item(Key.H) Then KeysPressed(7) = "h" Else KeysPressed(7) = ""
If State.Item(Key.I) Then KeysPressed(8) = "i" Else KeysPressed(8) = ""
If State.Item(Key.J) Then KeysPressed(9) = "j" Else KeysPressed(9) = ""
If State.Item(Key.K) Then KeysPressed(10) = "k" Else KeysPressed(10) = ""
If State.Item(Key.L) Then KeysPressed(11) = "l" Else KeysPressed(11) = ""
If State.Item(Key.M) Then KeysPressed(12) = "m" Else KeysPressed(12) = ""
If State.Item(Key.N) Then KeysPressed(13) = "n" Else KeysPressed(13) = ""
If State.Item(Key.O) Then KeysPressed(14) = "o" Else KeysPressed(14) = ""
If State.Item(Key.P) Then KeysPressed(15) = "p" Else KeysPressed(15) = ""
If State.Item(Key.Q) Then KeysPressed(16) = "q" Else KeysPressed(16) = ""
If State.Item(Key.R) Then KeysPressed(17) = "r" Else KeysPressed(17) = ""
If State.Item(Key.S) Then KeysPressed(18) = "s" Else KeysPressed(18) = ""
If State.Item(Key.T) Then KeysPressed(19) = "t" Else KeysPressed(19) = ""
If State.Item(Key.U) Then KeysPressed(20) = "u" Else KeysPressed(20) = ""
If State.Item(Key.V) Then KeysPressed(21) = "v" Else KeysPressed(21) = ""
If State.Item(Key.W) Then KeysPressed(22) = "w" Else KeysPressed(22) = ""
If State.Item(Key.X) Then KeysPressed(23) = "x" Else KeysPressed(23) = ""
If State.Item(Key.Y) Then KeysPressed(24) = "y" Else KeysPressed(24) = ""
If State.Item(Key.Z) Then KeysPressed(25) = "z" Else KeysPressed(25) = ""
If State.Item(Key.Escape) Then KeysPressed(26) = "escape" Else KeysPressed(26) = ""
If State.Item(Key.Space) Then KeysPressed(27) = "space" Else KeysPressed(27) = ""
If State.Item(Key.LeftControl) Then KeysPressed(28) = "control" Else KeysPressed(28) = ""
End Sub
End Class