DirectX:DirectInput:Tutorials:VBNET:DX9:Keyboard Handling
From GPWiki
Minimal code you can use to demonstrate how to get keyboard input using managed DX9 ...
Imports Microsoft.DirectX
Imports Microsoft.DirectX.DirectInput.CooperativeLevelFlags
Imports Microsoft.DirectX.DirectInput
Public Class Form1
Inherits System.Windows.Forms.Form
Dim KB As New DirectInput.Device(DirectInput.SystemGuid.Keyboard)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
KB.SetCooperativeLevel(Me, Background Or NonExclusive)
Me.Show()
KB.Acquire()
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
KB.Dispose()
KB = Nothing
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim State As DirectInput.KeyboardState
State = KB.GetCurrentKeyboardState
If State.Item(Key.Escape) Then Me.Close()
If State.Item(Key.A) Then Label1.Text &= "a"
If State.Item(Key.B) Then Label1.Text &= "b"
If State.Item(Key.C) Then Label1.Text &= "c"
End Sub
End Class