private void wiimote_WiimoteChanged(object sender, WiimoteChangedEventArgs e) { WiimoteState state = e.WiimoteState; BatteryLevel = state.Battery; A = state.ButtonState.A; B = state.ButtonState.B; Home = state.ButtonState.Home; Minus = state.ButtonState.Minus; Plus = state.ButtonState.Plus; One = state.ButtonState.One; Two = state.ButtonState.Two; Up = state.ButtonState.Up; Down = state.ButtonState.Down; Left = state.ButtonState.Left; Right = state.ButtonState.Right; // Nunchuck NunchukState nunchuk = state.NunchukState; C = nunchuk.C; Z = nunchuk.Z; NunchukX = nunchuk.Joystick.X; NunchukY = nunchuk.Joystick.Y; }
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); } } }
private static void MouseClick(NunchukState nunchukState) { if (!state.NunchukState.Z && nunchukState.Z) { MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.LeftDown | MouseOperations.MouseEventFlags.LeftUp); } }
private static void MoveMouse(NunchukState nunchukState) { var position = MouseOperations.GetCursorPosition(); var joyStickX = nunchukState.Joystick.X; var joyStickY = nunchukState.Joystick.Y; if (joyStickY > 0.05 || joyStickY < -0.05 || joyStickX > 0.05 || joyStickX < -0.05) { var posX = joyStickX > 0.1 ? position.X + _moveSpeed : position.X - _moveSpeed; var posY = joyStickY > 0.1 ? position.Y - _moveSpeed : position.Y + _moveSpeed; MouseOperations.SetCursorPosition(posX, posY); } }
private void UpdateNunchukState(NunchukState state, bool connected) { if (connected) { imageNunchuk.Opacity = 1.0; } else { imageNunchuk.Opacity = 0.4; } SetGlowState("C", state.C && connected); SetGlowState("Z", state.Z && connected); SetGlowState("Stick", state.Joystick.Length >= 0.085f && connected); }
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-"); } } }