Getting Input Via DirectInput

EliteELMO

Newcomer
Joined
Aug 3, 2005
Messages
6
I managed to get directX included in my VB .NET project, and I have assigned keys to use, but I am having an issue getting DirectInput to detect it.

I'm unsure as to how to go about this, so bear with me. I am uncertain as to how to detect the input of two keys (i.e: Right ALT and M at the same time), then making it call a function.

How would I go about doing this? I'd appreciate any help. Thanks.
 
Last edited:
Thi could possbily be what you are looking for. I wrote this class for a project I am working on. I hope somebody will find this useful.

Class Code
Visual Basic:
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

Usage
Visual Basic:
Dim KeyboardInput as New Keyboard_Handeler(Me)
               For i = 0 To 25
                    If KeyboardInput.KeysPressed(i) = "a" Then
                        lTemp2.TopLeft.X -= lKeyboardSensitivity

                        CameraPOS.X -= 0.1
                        LookingAT.X -= 0.1
                    End If
                    If KeyboardInput.KeysPressed(i) = "d" Then
                        lTemp2.TopLeft.X += lKeyboardSensitivity

                        CameraPOS.X += 0.1
                        LookingAT.X += 0.1
                    End If
                    If KeyboardInput.KeysPressed(i) = "w" Then
                        lTemp2.TopLeft.Y -= lKeyboardSensitivity

                        CameraPOS.Z += 0.1
                        LookingAT.Z += 0.1
                    End If
                    If KeyboardInput.KeysPressed(i) = "s" Then
                        lTemp2.TopLeft.Y += lKeyboardSensitivity

                        CameraPOS.Z -= 0.1
                        LookingAT.Z = 0.1
                    End If
                    If KeyboardInput.KeysPressed(i) = "p" Then
                        bTakeShot = True
                    End If
                Next
 
Back
Top