private void JoystickUpdateTick(object sender, EventArgs e) { JoystickMethods.joyGetPosEx(dev.id, out _joyInfo); _axisState[0] = _joyInfo.dwXpos; _axisState[1] = _joyInfo.dwYpos; _axisState[2] = _joyInfo.dwZpos; _axisState[3] = _joyInfo.dwRpos; _axisState[4] = _joyInfo.dwUpos; _axisState[5] = _joyInfo.dwVpos; pov = _joyInfo.dwPOV; // Take all button inputs. for (int i = 0; i < 32; i++) { var bitmask = _joyInfo.dwButtons & ((int)Math.Pow(2, i)); if (bitmask != 0) { // Pressed if (!_buttonState[i]) { // EVENT press if (State != null) { State(this, i, true); } if (Press != null) { Press(this, i); } } _buttonState[i] = true; } else { if (_buttonState[i]) { // EVENT release if (State != null) { State(this, i, false); } if (Release != null) { Release(this, i); } } _buttonState[i] = false; } } }
public static IEnumerable <JoystickInputDevice> Search() { List <JoystickInputDevice> Joysticks = new List <JoystickInputDevice>(); JOYCAPS CapturedJoysticks; uint devs = JoystickMethods.joyGetNumDevs(); for (deviceNumber = 0; deviceNumber < devs; deviceNumber++) { UInt32 res = JoystickMethods.joyGetDevCaps(deviceNumber, out CapturedJoysticks, JOYCAPS.Size); if (res != 165) { Joysticks.Add(new JoystickInputDevice(CapturedJoysticks, deviceNumber)); } } return(Joysticks); }