Exemplo n.º 1
0
        private void CheckAction(WiimoteState ws)
        {
            // マウスカーソル移動
            if (wmMouseActivated && !joyMouseActivated)
            {
                // マウスカーソルの移動
                MoveCursor(ws.AccelState.Values.X, ws.AccelState.Values.Y);
            }

            // ヌンチャク
            switch (ws.ExtensionType)
            {
            case ExtensionType.Nunchuk:
                // ヌンチャク刺さってるンゴ -> スティックでマウスカーソル移動
                var joy = ws.NunchukState.Joystick;

                if (previousNunchuk.C && !ws.NunchukState.C)
                {
                    wmMouseActivated  = false;
                    joyMouseActivated = !joyMouseActivated;
                    motionMouseToolStripMenuItem.Checked   = wmMouseActivated;
                    nunchuckMouseToolStripMenuItem.Checked = joyMouseActivated;
                }

                if (joyMouseActivated && !wmMouseActivated)
                {
                    if (ws.NunchukState.Z)
                    {
                        if (Math.Abs(joy.Y) >= 0.15)
                        {
                            WinAPI.mouse_event(WinAPI.MOUSEEVENTF_WHEEL, 0, 0, (int)(100 * joy.Y), 0);
                        }
                    }
                    else
                    {
                        if (Math.Abs(joy.X) >= 0.15)
                        {
                            MoveCursor(joy.X, 0);
                        }
                        if (Math.Abs(joy.Y) >= 0.15)
                        {
                            MoveCursor(0, -joy.Y);
                        }
                    }
                }

                previousNunchuk = ws.NunchukState;
                break;
            }

            // Aボタン (プレス)
            if (!previousBtns.A && ws.ButtonState.A)
            {
                // マウス左クリック
                WinAPI.mouse_event(WinAPI.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
            }

            // Aボタン (リリース)
            if (previousBtns.A && !ws.ButtonState.A)
            {
                // マウス左クリック
                WinAPI.mouse_event(WinAPI.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
            }

            // Bボタン (プレス)
            if (!previousBtns.B && ws.ButtonState.B)
            {
                // マウス右クリック
                WinAPI.mouse_event(WinAPI.MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
            }

            // Bボタン (リリース)
            if (previousBtns.B && !ws.ButtonState.B)
            {
                // マウス右クリック
                WinAPI.mouse_event(WinAPI.MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
            }

            // +ボタン
            if (previousBtns.Plus && !ws.ButtonState.Plus && (wmMouseActivated || joyMouseActivated))
            {
                // カーソルスピード加速
                mouseSpeed += 5;
            }

            // -ボタン
            if (previousBtns.Minus && !ws.ButtonState.Minus && (wmMouseActivated || joyMouseActivated))
            {
                // カーソルスピード減速
                mouseSpeed -= 5;
                if (mouseSpeed <= 0)
                {
                    mouseSpeed = 1;
                }
            }

            // ↑ボタン
            if (ws.ButtonState.Up && !ws.ButtonState.Two)
            {
                // マウスホイール 上
                WinAPI.mouse_event(WinAPI.MOUSEEVENTF_WHEEL, 0, 0, 65, 0);
            }

            if (previousBtns.Up && !ws.ButtonState.Up && ws.ButtonState.Two)
            {
                // 音量+
                volChanged = true;
                var vol = device.AudioEndpointVolume.MasterVolumeLevelScalar;
                device.AudioEndpointVolume.MasterVolumeLevelScalar += vol <= 1.0f - 0.05f ? 0.05f : 1.0f - vol;
            }

            // ↓ボタン
            if (ws.ButtonState.Down && !ws.ButtonState.Two)
            {
                // マウスホイール 下
                WinAPI.mouse_event(WinAPI.MOUSEEVENTF_WHEEL, 0, 0, -65, 0);
            }

            if (previousBtns.Down && !ws.ButtonState.Down && ws.ButtonState.Two)
            {
                // 音量-
                volChanged = true;
                var vol = device.AudioEndpointVolume.MasterVolumeLevelScalar;
                device.AudioEndpointVolume.MasterVolumeLevelScalar -= vol >= 0.05f ? 0.05f : vol;
            }

            // →ボタン
            if (previousBtns.Right && !ws.ButtonState.Right)
            {
                // マウスカーソルを画面の真ん中に
                var s = Screen.FromPoint(Cursor.Position);
                CursorPoint     = new System.Drawing.Point(s.Bounds.X + s.Bounds.Width / 2, s.Bounds.Y + s.Bounds.Height / 2);
                Cursor.Position = CursorPoint;
            }

            // ←ボタン
            if (previousBtns.Left && !ws.ButtonState.Left)
            {
                // ウィンドウの表示・非表示
                if (this.Visible)
                {
                    // トレーに格納
                    this.Visible       = false;
                    this.ShowInTaskbar = false;
                    this.WindowState   = FormWindowState.Minimized;
                }
                else
                {
                    // 表示
                    this.Visible       = true;
                    this.ShowInTaskbar = true;
                    this.WindowState   = FormWindowState.Normal;
                    this.Activate();
                }
            }

            // 1ボタン
            if (previousBtns.One && !ws.ButtonState.One)
            {
                // Windowsキー
                SendKeys.Send("^{ESC}");
            }

            if (previousBtns.Two && !ws.ButtonState.Two)
            {
                if (!volChanged)
                {
                    // ミュート
                    device.AudioEndpointVolume.Mute = !device.AudioEndpointVolume.Mute;
                }
                volChanged = false;
            }

            // Homeボタン
            if (previousBtns.Home && !ws.ButtonState.Home)
            {
                // マウス有効化設定
                wmMouseActivated = !wmMouseActivated;
                if (wmMouseActivated)
                {
                    joyMouseActivated = false;
                    mWiimote.SetLEDs(true, true, true, true);
                    notifyIcon1.Text = "Wiimote Mouse : Enabled";
                }
                else
                {
                    mWiimote.SetLEDs(true, false, false, true);
                    notifyIcon1.Text = "Wiimote Mouse : Disabled";
                }

                motionMouseToolStripMenuItem.Checked   = wmMouseActivated;
                nunchuckMouseToolStripMenuItem.Checked = joyMouseActivated;
            }
        }
Exemplo n.º 2
0
        public void updateNunchuk(NunchukState nunchuk)
        {
            JToken key = this.jsonObj.GetValue("Nunchuk.StickX");
            if (key != null)
            {
                string handle = key.ToString().ToLower();

                if (handle.Length > 4 && handle.Substring(0, 4).Equals("360."))
                {
                    this.xinputUpdateAnalog(handle.Substring(4), nunchuk.Joystick.X + 0.5);
                }
            }

            key = this.jsonObj.GetValue("Nunchuk.StickY");
            if (key != null)
            {
                string handle = key.ToString().ToLower();

                if (handle.Length > 4 && handle.Substring(0, 4).Equals("360."))
                {
                    this.xinputUpdateAnalog(handle.Substring(4), nunchuk.Joystick.Y + 0.5);
                }
            }
        }
Exemplo n.º 3
0
        public void updateNunchuk(NunchukState nunchuk)
        {
            KeymapOutConfig outConfig;

            if (this.config.TryGetValue("Nunchuk.StickRight", out outConfig))
            {
                if (nunchuk.Joystick.X > 0)
                {
                    updateStickHandlers(outConfig, nunchuk.Joystick.X * 2);
                }
                else if (nunchuk.Joystick.X == 0)
                {
                    updateStickHandlers(outConfig, 0);
                }

                if (nunchuk.Joystick.X * 2 > outConfig.Threshold && !PressedButtons["Nunchuk.StickRight"])
                {
                    PressedButtons["Nunchuk.StickRight"] = true;
                    this.executeButtonDown("Nunchuk.StickRight");
                }
                else if (nunchuk.Joystick.X * 2 < outConfig.Threshold && PressedButtons["Nunchuk.StickRight"])
                {
                    PressedButtons["Nunchuk.StickRight"] = false;
                    this.executeButtonUp("Nunchuk.StickRight");
                }
            }

            if (this.config.TryGetValue("Nunchuk.StickLeft", out outConfig))
            {
                if (nunchuk.Joystick.X < 0)
                {
                    updateStickHandlers(outConfig, nunchuk.Joystick.X * -2);
                }
                else if (nunchuk.Joystick.X == 0)
                {
                    updateStickHandlers(outConfig, 0);
                }

                if (nunchuk.Joystick.X * -2 > outConfig.Threshold && !PressedButtons["Nunchuk.StickLeft"])
                {
                    PressedButtons["Nunchuk.StickLeft"] = true;
                    this.executeButtonDown("Nunchuk.StickLeft");
                }
                else if (nunchuk.Joystick.X * -2 < outConfig.Threshold && PressedButtons["Nunchuk.StickLeft"])
                {
                    PressedButtons["Nunchuk.StickLeft"] = false;
                    this.executeButtonUp("Nunchuk.StickLeft");
                }
            }
            if (this.config.TryGetValue("Nunchuk.StickUp", out outConfig))
            {
                if (nunchuk.Joystick.Y > 0)
                {
                    updateStickHandlers(outConfig, nunchuk.Joystick.Y * 2);
                }
                else if (nunchuk.Joystick.Y == 0)
                {
                    updateStickHandlers(outConfig, 0);
                }

                if (nunchuk.Joystick.Y * 2 > outConfig.Threshold && !PressedButtons["Nunchuk.StickUp"])
                {
                    PressedButtons["Nunchuk.StickUp"] = true;
                    this.executeButtonDown("Nunchuk.StickUp");
                }
                else if (nunchuk.Joystick.Y * 2 < outConfig.Threshold && PressedButtons["Nunchuk.StickUp"])
                {
                    PressedButtons["Nunchuk.StickUp"] = false;
                    this.executeButtonUp("Nunchuk.StickUp");
                }

            }
            if (this.config.TryGetValue("Nunchuk.StickDown", out outConfig))
            {
                if (nunchuk.Joystick.Y < 0)
                {
                    updateStickHandlers(outConfig, nunchuk.Joystick.Y * -2);
                }
                else if (nunchuk.Joystick.Y == 0)
                {
                    updateStickHandlers(outConfig, 0);
                }

                if (nunchuk.Joystick.Y * -2 > outConfig.Threshold && !PressedButtons["Nunchuk.StickDown"])
                {
                    PressedButtons["Nunchuk.StickDown"] = true;
                    this.executeButtonDown("Nunchuk.StickDown");
                }
                else if (nunchuk.Joystick.Y * -2 < outConfig.Threshold && PressedButtons["Nunchuk.StickDown"])
                {
                    PressedButtons["Nunchuk.StickDown"] = false;
                    this.executeButtonUp("Nunchuk.StickDown");
                }
            }

            AccelState accelState = nunchuk.AccelState;

            if (this.config.TryGetValue("Nunchuk.AccelX+", out outConfig))
            {
                if (accelState.Values.X > 0)
                {
                    updateStickHandlers(outConfig, accelState.Values.X );
                }
                else if (accelState.Values.X == 0)
                {
                    updateStickHandlers(outConfig, 0);
                }

                if (accelState.Values.X * 2 > outConfig.Threshold && !PressedButtons["Nunchuk.AccelX+"])
                {
                    PressedButtons["Nunchuk.AccelX+"] = true;
                    this.executeButtonDown("Nunchuk.AccelX+");
                }
                else if (accelState.Values.X * 2 < outConfig.Threshold && PressedButtons["Nunchuk.AccelX+"])
                {
                    PressedButtons["Nunchuk.AccelX+"] = false;
                    this.executeButtonUp("Nunchuk.AccelX+");
                }
            }
            if (this.config.TryGetValue("Nunchuk.AccelX-", out outConfig))
            {
                if (accelState.Values.X < 0)
                {
                    updateStickHandlers(outConfig, accelState.Values.X * -1);
                }
                else if (accelState.Values.X == 0)
                {
                    updateStickHandlers(outConfig, 0);
                }

                if (accelState.Values.X * -2 > outConfig.Threshold && !PressedButtons["Nunchuk.AccelX-"])
                {
                    PressedButtons["Nunchuk.AccelX-"] = true;
                    this.executeButtonDown("Nunchuk.AccelX-");
                }
                else if (accelState.Values.X * -2 < outConfig.Threshold && PressedButtons["Nunchuk.AccelX-"])
                {
                    PressedButtons["Nunchuk.AccelX-"] = false;
                    this.executeButtonUp("Nunchuk.AccelX-");
                }
            }
            if (this.config.TryGetValue("Nunchuk.AccelY+", out outConfig))
            {
                if (accelState.Values.Y > 0)
                {
                    updateStickHandlers(outConfig, accelState.Values.Y);
                }
                else if (accelState.Values.Y == 0)
                {
                    updateStickHandlers(outConfig, 0);
                }

                if (accelState.Values.Y * 2 > outConfig.Threshold && !PressedButtons["Nunchuk.AccelY+"])
                {
                    PressedButtons["Nunchuk.AccelY+"] = true;
                    this.executeButtonDown("Nunchuk.AccelY+");
                }
                else if (accelState.Values.Y * 2 < outConfig.Threshold && PressedButtons["Nunchuk.AccelY+"])
                {
                    PressedButtons["Nunchuk.AccelY+"] = false;
                    this.executeButtonUp("Nunchuk.AccelY+");
                }
            }
            if (this.config.TryGetValue("Nunchuk.AccelY-", out outConfig))
            {
                if (accelState.Values.Y < 0)
                {
                    updateStickHandlers(outConfig, accelState.Values.Y * -1);
                }
                else if (accelState.Values.Y == 0)
                {
                    updateStickHandlers(outConfig, 0);
                }

                if (accelState.Values.Y * -2 > outConfig.Threshold && !PressedButtons["Nunchuk.AccelY-"])
                {
                    PressedButtons["Nunchuk.AccelY-"] = true;
                    this.executeButtonDown("Nunchuk.AccelY-");
                }
                else if (accelState.Values.Y * -2 < outConfig.Threshold && PressedButtons["Nunchuk.AccelY-"])
                {
                    PressedButtons["Nunchuk.AccelY-"] = false;
                    this.executeButtonUp("Nunchuk.AccelY-");
                }
            }
            if (this.config.TryGetValue("Nunchuk.AccelZ+", out outConfig))
            {
                if (accelState.Values.Z > 0)
                {
                    updateStickHandlers(outConfig, accelState.Values.Z);
                }
                else if (accelState.Values.Z == 0)
                {
                    updateStickHandlers(outConfig, 0);
                }

                if (accelState.Values.Z * 2 > outConfig.Threshold && !PressedButtons["Nunchuk.AccelZ+"])
                {
                    PressedButtons["Nunchuk.AccelZ+"] = true;
                    this.executeButtonDown("Nunchuk.AccelZ+");
                }
                else if (accelState.Values.Z * 2 < outConfig.Threshold && PressedButtons["Nunchuk.AccelZ+"])
                {
                    PressedButtons["Nunchuk.AccelZ+"] = false;
                    this.executeButtonUp("Nunchuk.AccelZ+");
                }
            }
            if (this.config.TryGetValue("Nunchuk.AccelZ-", out outConfig))
            {
                if (accelState.Values.Z < 0)
                {
                    updateStickHandlers(outConfig, accelState.Values.Z * -1);
                }
                else if (accelState.Values.Z == 0)
                {
                    updateStickHandlers(outConfig, 0);
                }

                if (accelState.Values.Z * -2 > outConfig.Threshold && !PressedButtons["Nunchuk.AccelZ-"])
                {
                    PressedButtons["Nunchuk.AccelZ-"] = true;
                    this.executeButtonDown("Nunchuk.AccelZ-");
                }
                else if (accelState.Values.Z * -2 < outConfig.Threshold && PressedButtons["Nunchuk.AccelZ-"])
                {
                    PressedButtons["Nunchuk.AccelZ-"] = false;
                    this.executeButtonUp("Nunchuk.AccelZ-");
                }
            }
        }