// Initialize this Joystick controller //-------------------------------------------------------------------------- // Construction //-------------------------------------------------------------------------- public JoystickController(DirectInput dinput, Guid guid) { this.directInputDevice = dinput.CreateDevice(guid); foreach (DIDEVICEOBJECTINSTANCE ddoi in this.directInputDevice.EnumObjects(DIDFT.AXIS)) { if ((ddoi.dwType & (int)DIDFT.AXIS) != 0) // can omit? { this.directInputDevice.SetRange(ddoi, -128, 127); } } // We stick formatDesc in a member variable because we're not sure whether // we're allowed to free it right after the SetDataFormat call or whether // we're responsible for keeping it alive so long as we use the IDirectInputDevice8 // instance. this.formatDesc = State.GetDataRetrievalDescriptor(); this.directInputDevice.SetDataFormat(ref this.formatDesc); }
// Populate the Controllers variable with all the attached controllers public static void FindJoystickControllers() { DirectInput dinput = new DirectInput(); foreach (DIDEVICEINSTANCEW device in dinput.EnumDevices(DI8DEVTYPE.CLASS_GAMECTRL, DIEDFL.ATTACHEDONLY)) { JoystickController jyc = new JoystickController(dinput, device.guidInstance); JoystickController.Controllers.Add(jyc); } }