/// <summary> /// 根据游戏手柄的Id实例化 /// </summary> /// <param name="joystickId"></param> public Joystick(int joystickId) { this.Id = joystickId; this.JoystickCAPS = new JoystickAPI.JOYCAPS(); //取得游戏手柄的参数信息 if (JoystickAPI.joyGetDevCaps(joystickId, ref this.JoystickCAPS, Marshal.SizeOf(typeof(JoystickAPI.JOYCAPS))) == JoystickAPI.JOYERR_NOERROR) { this.IsConnected = true; this.Name = this.JoystickCAPS.szPname; } else { this.IsConnected = false; } }
/// <summary> /// 定时器的回调方法 /// </summary> /// <param name="state"></param> //private void OnTimerCallback(object state) public JoystickHandle OnTimerCallback() { JoyHandle = new JoystickHandle(); JoystickAPI.JOYINFOEX infoEx = new JoystickAPI.JOYINFOEX(); infoEx.dwSize = Marshal.SizeOf(typeof(JoystickAPI.JOYINFOEX)); infoEx.dwFlags = (int)JoystickAPI.JOY_RETURNBUTTONS; int result = JoystickAPI.joyGetPosEx(this.Id, ref infoEx); if (result == JoystickAPI.JOYERR_NOERROR) { JoyHandle.Xpos = infoEx.dwXpos; JoyHandle.Ypos = infoEx.dwYpos; JoyHandle.Zpos = infoEx.dwZpos; JoyHandle.Rpos = infoEx.dwRpos; } return(JoyHandle); }