ben_dover
06-21-2006, 07:18 AM
Hi I just found this code on some wiki website (http://gpwiki.org/index.php/DirectX:Tutorials) about DirectX9.
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
Now I have a form which is going to be where the user determines their control settings. This form has a few textboxes and 2 command buttons. I'd like to change the above code so it depends on what textbox currently has focus (that the text changes). I've tried putting the code under the timer in a KeyDown event for the textbox and it doesn't work.
Please help, how can I get this to do what I want???
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
Now I have a form which is going to be where the user determines their control settings. This form has a few textboxes and 2 command buttons. I'd like to change the above code so it depends on what textbox currently has focus (that the text changes). I've tried putting the code under the timer in a KeyDown event for the textbox and it doesn't work.
Please help, how can I get this to do what I want???