internal static void RefreshJoysticks()
{
int j = 0;
for (int i = 0; i < 10; i++)
{
//This *only* instanciates the first joystick, as OpenTK seems to loop
//the first joystick into any unused slots, and doesn't provide a name
//we can test against to see if it's the same
//Must be fixable, need to think on it....
var state = OpenTK.Input.Joystick.GetState(i);
var description = OpenTK.Input.Joystick.GetCapabilities(i).ToString();
if (description == "{Axes: 0; Buttons: 0; Hats: 0; IsConnected: True}")
{
break;
}
if (state.IsConnected)
{
j++;
}
}
for (int i = 0; i < j; i++)
{
AttachedJoysticks = new Joystick[j];
var state = OpenTK.Input.Joystick.GetState(i);
if (state.IsConnected)
{
Joystick newJoystick = new Joystick
{
Name = "Joystick" + i,
OpenTKHandle = i,
};
AttachedJoysticks[i] = newJoystick;
}
}
}