示例#1
0
        /// <summary>
        /// 前一次的处于按下状态的按钮
        /// </summary>

        //直接初始化
        //遍历手柄ID寻找
        public Joystick()
        {
            int IDmax = 2, i = 0;
            int joystickId;

            this.JoystickCAPS = new JoystickAPI.JOYCAPS();
            for (; i < IDmax; i++)
            {
                joystickId = i;
                if (JoystickAPI.joyGetDevCaps(joystickId, ref this.JoystickCAPS, Marshal.SizeOf(typeof(JoystickAPI.JOYCAPS)))
                    == JoystickAPI.JOYERR_NOERROR)
                {
                    this.IsConnected = true;
                    this.Name        = this.JoystickCAPS.szPname;
                    i = IDmax + 1;
                }
                else
                {
                    this.IsConnected = false;
                }
            }
            if (i == IDmax)
            {
                System.Windows.MessageBox.Show("未插入摇杆", "ERROR");
                Environment.Exit(0);
            }

            //取得游戏手柄的参数信息
        }
示例#2
0
        /// <summary>
        /// 根据游戏手柄的Id实例化
        /// </summary>
        /// <param name="joystickId"></param>
        public Joystick(int joystickId)
        {
            this.Id           = joystickId;
            this.JoystickCAPS = new JoystickAPI.JOYCAPS();


            int test = JoystickAPI.joyGetDevCaps(joystickId, ref this.JoystickCAPS, Marshal.SizeOf(typeof(JoystickAPI.JOYCAPS)));

            //取得游戏手柄的参数信息
            if (test
                == JoystickAPI.JOYERR_NOERROR)
            {
                this.IsConnected = true;
                System.Console.WriteLine(JoystickAPI.joyGetNumDevs());
                this.Name = this.JoystickCAPS.szPname;
            }
            else
            {
                this.IsConnected = false;
                //System.Windows.MessageBox.Show("ID为" + joystickId + "的摇杆未插入", "ERROR");
                //Environment.Exit(0);
            }
        }