-
Notifications
You must be signed in to change notification settings - Fork 1
/
Controller.cs
56 lines (48 loc) · 1.2 KB
/
Controller.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using SlimDX.DirectInput;
using System.Collections.Generic;
class Controller
{
private static DirectInput _joystick = new DirectInput();
private static JoystickState _state = new JoystickState();
private static Joystick[] _sticks;
public bool[] _pressedButtons;
public bool _isStickEnabled = false;
public Controller()
{
getSticks();
if (_sticks.Length > 0)
{
_isStickEnabled = true;
}
}
public static void getSticks()
{
List<Joystick> sticks = new List<Joystick>();
foreach (DeviceInstance device in _joystick.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
{
try
{
Joystick stick = new Joystick(_joystick, device.InstanceGuid);
stick.Acquire();
foreach (DeviceObjectInstance deviceObject in stick.GetObjects())
{
if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
stick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-100, 100);
}
sticks.Add(stick);
}
catch (DirectInputException)
{
}
}
_sticks = sticks.ToArray();
}
public void GetState()
{
if (_sticks != null)
{
_state = _sticks[0].GetCurrentState();
_pressedButtons = _state.GetButtons();
}
}
}