Imports
System.Globalization
Imports
System.Windows.Forms
Imports
SlimDX
Imports
SlimDX.DirectInput
Imports
System.Collections.Generic
Partial
Public
Class
Form1
Inherits
Form
Private
joystick
As
Joystick
Private
state
As
New
JoystickState()
Private
numPOVs
As
Integer
Private
SliderCount
As
Integer
Private
Sub
Form1_Load(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
MyBase
.Load
End
Sub
Private
Sub
Button1_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
Button1.Click
If
joystick
Is
Nothing
Then
CreateDevice()
Else
ReleaseDevice()
End
If
UpdateUI()
End
Sub
Private
Sub
UpdateUI()
If
joystick
Is
Nothing
Then
Button1.Text =
"Create Device"
Else
Button1.Text =
"Release Device"
End
If
Dim
strText
As
String
=
Nothing
OSY:
Label1.Text = state.X.ToString(CultureInfo.CurrentCulture)
ProgressBar1.Value = state.X.ToString(CultureInfo.CurrentCulture) + 1000
Label2.Text = state.Y.ToString(CultureInfo.CurrentCulture)
ProgressBar2.Value = state.Y.ToString(CultureInfo.CurrentCulture) + 1000
Label3.Text = state.Z.ToString(CultureInfo.CurrentCulture)
ROTACE:
Label4.Text = state.RotationX.ToString(CultureInfo.CurrentCulture)
Label5.Text = state.RotationY.ToString(CultureInfo.CurrentCulture)
Label6.Text = state.RotationZ.ToString(CultureInfo.CurrentCulture)
ProgressBar3.Value = state.RotationZ.ToString(CultureInfo.CurrentCulture) + 1000
PLYN:
Dim
slider
As
Integer
() = state.GetSliders()
Label7.Text = slider(0).ToString(CultureInfo.CurrentCulture)
ProgressBar4.Value = slider(0).ToString(CultureInfo.CurrentCulture) + 1000
label21.Text = slider(1).ToString(CultureInfo.CurrentCulture)
PADY:
Dim
pov
As
Integer
() = state.GetPointOfViewControllers()
Label8.Text = pov(0).ToString(CultureInfo.CurrentCulture)
If
CInt
(Label8.Text) = -1
Then
LineShape1.Y1 = 79
LineShape1.X1 = 346
ElseIf
CInt
(Label8.Text) = 0
Then
LineShape1.Y1 = 51
LineShape1.X1 = 346
ElseIf
CInt
(Label8.Text) = 31500
Then
LineShape1.Y1 = 62
LineShape1.X1 = 323
ElseIf
CInt
(Label8.Text) = 27000
Then
LineShape1.Y1 = 81
LineShape1.X1 = 314
ElseIf
CInt
(Label8.Text) = 22500
Then
LineShape1.Y1 = 100
LineShape1.X1 = 323
ElseIf
CInt
(Label8.Text) = 18000
Then
LineShape1.Y1 = 111
LineShape1.X1 = 346
ElseIf
CInt
(Label8.Text) = 13500
Then
LineShape1.Y1 = 100
LineShape1.X1 = 369
ElseIf
CInt
(Label8.Text) = 9000
Then
LineShape1.Y1 = 81
LineShape1.X1 = 378
ElseIf
CInt
(Label8.Text) = 4500
Then
LineShape1.Y1 = 62
LineShape1.X1 = 369
End
If
Label9.Text = pov(1).ToString(CultureInfo.CurrentCulture)
Label22.Text = pov(2).ToString(CultureInfo.CurrentCulture)
Label23.Text = pov(3).ToString(CultureInfo.CurrentCulture)
TLAČÍTKA:
Dim
buttons
As
Boolean
() = state.GetButtons()
For
b
As
Integer
= 0
To
buttons.Length - 1
If
buttons(b)
Then
strText += b.ToString(
"00 "
, CultureInfo.CurrentCulture)
End
If
Next
Label13.Text = strText
End
Sub
Private
Sub
ReleaseDevice()
Timer1.[
Stop
]()
If
joystick IsNot
Nothing
Then
joystick.Unacquire()
joystick.Dispose()
End
If
joystick =
Nothing
End
Sub
Private
Sub
CreateDevice()
Dim
dinput
As
New
DirectInput()
For
Each
device
As
DeviceInstance
In
dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly)
Try
joystick =
New
Joystick(dinput, device.InstanceGuid)
joystick.SetCooperativeLevel(
Me
, CooperativeLevel.Exclusive
Or
CooperativeLevel.Foreground)
Exit
Try
Catch
generatedExceptionName
As
DirectInputException
End
Try
Next
If
joystick
Is
Nothing
Then
MessageBox.Show(
"There are no joysticks attached to the system."
)
Return
End
If
For
Each
deviceObject
As
DeviceObjectInstance
In
joystick.GetObjects()
If
(deviceObject.ObjectType
And
ObjectDeviceType.Axis) <> 0
Then
joystick.GetObjectPropertiesById(
CInt
(deviceObject.ObjectType)).SetRange(-1000, 1000)
End
If
Unlocking(deviceObject)
Next
joystick.Acquire()
Timer1.Interval = 1000 \ 24
Timer1.Start()
End
Sub
Private
Sub
Unlocking(
ByVal
d
As
DeviceObjectInstance)
If
ObjectGuid.XAxis = d.ObjectTypeGuid
Then
Label1.Enabled =
True
End
If
If
ObjectGuid.YAxis = d.ObjectTypeGuid
Then
Label2.Enabled =
True
End
If
If
ObjectGuid.ZAxis = d.ObjectTypeGuid
Then
Label3.Enabled =
True
End
If
If
ObjectGuid.RotationalXAxis = d.ObjectTypeGuid
Then
Label18.Enabled =
True
End
If
If
ObjectGuid.RotationalYAxis = d.ObjectTypeGuid
Then
Label19.Enabled =
True
End
If
If
ObjectGuid.RotationalZAxis = d.ObjectTypeGuid
Then
Label6.Enabled =
True
End
If
If
ObjectGuid.Slider = d.ObjectTypeGuid
Then
Select
Case
System.Math.Max(System.Threading.Interlocked.Increment(SliderCount), SliderCount - 1)
Case
0
Label21.Enabled =
True
Exit
Select
Case
1
Label7.Enabled =
True
Exit
Select
End
Select
End
If
If
ObjectGuid.PovController = d.ObjectTypeGuid
Then
Select
Case
System.Math.Max(System.Threading.Interlocked.Increment(numPOVs), numPOVs - 1)
Case
0
Label9.Enabled =
True
Exit
Select
Case
1
Label8.Enabled =
True
Exit
Select
Case
2
Label22.Enabled =
True
Exit
Select
Case
3
Label23.Enabled =
True
Exit
Select
End
Select
End
If
End
Sub
Private
Sub
Timer1_Tick(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
Timer1.Tick
ReadImmediateData()
End
Sub
Private
Sub
ReadImmediateData()
If
joystick.Acquire().IsFailure
Then
Return
End
If
If
joystick.Poll().IsFailure
Then
Return
End
If
state = joystick.GetCurrentState()
If
Result.Last.IsFailure
Then
Return
End
If
UpdateUI()
End
Sub
Private
Sub
Button2_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
Button2.Click
End
Sub
End
Class