void RelinquishDevice(uint deviceID) { ownedDevices.Remove(deviceID); pressedButtons.Remove(deviceID); var args = new JoystickDeviceEventArgs(); args.DeviceID = deviceID; OnJoystickRelinquished(args); }
void OnJoystickRelinquished(object joystick, JoystickDeviceEventArgs e) { // once a device is no longer used by any clients it should get relinquished if (joysticks.Any(j => j.IsDeviceOwned(e.DeviceID))) { return; } joystickManager.RelinquishDevice(e.DeviceID); Console.WriteLine("Relinquished device {0}", e.DeviceID); }
void RequestDevice(uint deviceID) { var args = new JoystickDeviceEventArgs(); args.DeviceID = deviceID; OnJoystickRequested(args); if (args.Acquired) { ownedDevices.Add(deviceID); pressedButtons.Add(deviceID, new List <byte> { }); } }
public void OnDisconnected() { var ownedDevices2 = new List <uint>(ownedDevices); ownedDevices.Clear(); foreach (var device in ownedDevices2) { foreach (var button in pressedButtons[device]) { var args = new JoystickEventArgs(); args.DeviceID = device; args.Button = button; OnButtonReleased(args); } var args2 = new JoystickDeviceEventArgs(); args2.DeviceID = device; OnJoystickRelinquished(args2); } pressedButtons.Clear(); }
void OnJoystickRequested(object joystick, JoystickDeviceEventArgs e) { var acquired = joystickManager.AcquireDevice(e.DeviceID); e.Acquired = acquired; }
protected virtual void OnJoystickRelinquished(JoystickDeviceEventArgs e) { JoystickRelinquished?.Invoke(this, e); }