Ich weiß wir hatten das Thema schon oft ...
Leider bin ich trotzdem noch zu keiner Lösung gekommen.
Mein bisheriger Code sieht so aus:
Ich weiß der Code ist lang, aber bitte schaut ihn euch doch nochmal an und helft mir weiter, ich verzweifel sonst noch irgendwann
Danke für eure Hilfe
Leider bin ich trotzdem noch zu keiner Lösung gekommen.
Mein bisheriger Code sieht so aus:
Quellcode
- Imports System
- Imports System.Windows.Forms
- Imports Microsoft.DirectX.DirectInput
- Imports Microsoft.DirectX
- Public Class Joystick
- Private applicationDevice As Device = Nothing
- Public Shared state As New JoystickState()
- Public Function InitDirectInput() As Boolean 'wir erstellen eine Funktion die die Verbindung zum Joystick herstellt
- Dim instance As DeviceInstance
- For Each instance In Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly)
- applicationDevice = New Device(instance.InstanceGuid)
- Exit For
- Next instance
- applicationDevice.SetDataFormat(DeviceDataFormat.Joystick)
- applicationDevice.SetCooperativeLevel(Me, CooperativeLevelFlags.Exclusive Or CooperativeLevelFlags.Foreground)
- Dim d As DeviceObjectInstance
- For Each d In applicationDevice.Objects
- If 0 <> (d.ObjectId And CInt(DeviceObjectTypeFlags.Axis)) Then
- ' Set the range for the axis.
- applicationDevice.Properties.SetRange(ParameterHow.ById, d.ObjectId, New InputRange(-100000, +100000)) 'hier kann man die Auflösung des Joysticks beliebig einstellen
- End If
- Next d
- Return True
- End Function 'InitDirectInput
- Public Sub GetData()
- If Nothing Is applicationDevice Then
- Return
- End If
- Try
- applicationDevice.Poll()
- Catch inputex As InputException
- If TypeOf inputex Is NotAcquiredException Or TypeOf inputex Is InputLostException Then
- Try
- applicationDevice.Acquire()
- Catch
- Return
- End Try
- End If
- End Try
- Try
- state = applicationDevice.CurrentJoystickState
- Catch
- Return
- End Try
- End Sub 'GetData
- Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
- GetData() 'Joystick Position erfassen
- Label1.Text = "Joystick: X = " + state.X.ToString() + " Y = " + state.Y.ToString() ' Anzeigen wo der Joystick grad ist
- Label3.Text = "Joystick: Z achse= " & state.Z.ToString 'Anzeige des Geschwindigkeitsreglers
- Label4.Text = "Joystick: Z rotation= " & state.Rz.ToString 'Anzeige der rechts links Rotation
- End Sub
- Private Sub Joystick_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Button1.Click
- Try
- InitDirectInput()
- Catch
- MsgBox("Es konnte kein Joystick gefunden werden" & vbCrLf & "Bitte überprüfen sie die Verbindung")
- End Try
- End Sub
- End Class
Ich weiß der Code ist lang, aber bitte schaut ihn euch doch nochmal an und helft mir weiter, ich verzweifel sonst noch irgendwann
Danke für eure Hilfe