private void MouseEvent(int deltaX, int deltaY, bool right, bool left) { #if TRACE Trace.WriteLine(String.Format("Mouse: DX {0}, DY {1}, Right: {2}, Left: {3}", deltaX, deltaY, right, left)); #endif if (!_config.EnableMouseInput) { return; } #region Buttons Mouse.MouseEvents buttons = Mouse.MouseEvents.None; if ((_mouseButtons & Mouse.MouseEvents.RightDown) != 0) { if (!right) { buttons |= Mouse.MouseEvents.RightUp; _mouseButtons &= ~Mouse.MouseEvents.RightDown; } } else { if (right) { buttons |= Mouse.MouseEvents.RightDown; _mouseButtons |= Mouse.MouseEvents.RightDown; } } if ((_mouseButtons & Mouse.MouseEvents.LeftDown) != 0) { if (!left) { buttons |= Mouse.MouseEvents.LeftUp; _mouseButtons &= ~Mouse.MouseEvents.LeftDown; } } else { if (left) { buttons |= Mouse.MouseEvents.LeftDown; _mouseButtons |= Mouse.MouseEvents.LeftDown; } } if (buttons != Mouse.MouseEvents.None) { if (_config.HandleMouseLocally) { Mouse.Button(buttons); } } #endregion Buttons #region Movement Delta deltaX = (int)(deltaX * _config.MouseSensitivity); deltaY = (int)(deltaY * _config.MouseSensitivity); if (deltaX != 0 || deltaY != 0) { if (_config.HandleMouseLocally) { Mouse.Move(deltaX, deltaY, false); } } #endregion Movement Delta if (!_config.HandleMouseLocally) { MouseCallback(Name, deltaX, deltaY, (int)buttons); } }
private void WiimoteChanged(object sender, WiimoteChangedEventArgs args) { WiimoteState ws = args.WiimoteState; if (_previousState != null) { if (ws.ButtonState.A && !_previousState.ButtonState.A) { RemoteCallback(Name, "Wiimote_Button:A"); } if (ws.ButtonState.B && !_previousState.ButtonState.B) { RemoteCallback(Name, "Wiimote_Button:B"); } if (ws.ButtonState.Home && !_previousState.ButtonState.Home) { RemoteCallback(Name, "Wiimote_Button:Home"); } if (ws.ButtonState.Minus && !_previousState.ButtonState.Minus) { RemoteCallback(Name, "Wiimote_Button:Minus"); } if (ws.ButtonState.One && !_previousState.ButtonState.One) { RemoteCallback(Name, "Wiimote_Button:One"); } if (ws.ButtonState.Plus && !_previousState.ButtonState.Plus) { RemoteCallback(Name, "Wiimote_Button:Plus"); } if (ws.ButtonState.Two && !_previousState.ButtonState.Two) { RemoteCallback(Name, "Wiimote_Button:Two"); } if (ws.ButtonState.Down && !_previousState.ButtonState.Down) { RemoteCallback(Name, "Wiimote_Pad:Down"); } if (ws.ButtonState.Left && !_previousState.ButtonState.Left) { RemoteCallback(Name, "Wiimote_Pad:Left"); } if (ws.ButtonState.Right && !_previousState.ButtonState.Right) { RemoteCallback(Name, "Wiimote_Pad:Right"); } if (ws.ButtonState.Up && !_previousState.ButtonState.Up) { RemoteCallback(Name, "Wiimote_Pad:Up"); } if (ws.ExtensionType == ExtensionType.Nunchuk) { if (_useNunchukAsMouse) // Use nunchuk as mouse? { Mouse.MouseEvents mouseButtons = Mouse.MouseEvents.None; if (ws.NunchukState.C != _previousState.NunchukState.C) { mouseButtons |= ws.NunchukState.C ? Mouse.MouseEvents.RightDown : Mouse.MouseEvents.RightUp; } if (ws.NunchukState.Z != _previousState.NunchukState.Z) { mouseButtons |= ws.NunchukState.Z ? Mouse.MouseEvents.LeftDown : Mouse.MouseEvents.LeftUp; } int deltaX = (int)(ws.NunchukState.Joystick.X * 10 * _mouseSensitivity); int deltaY = (int)(ws.NunchukState.Joystick.Y * -10 * _mouseSensitivity); if (_handleMouseLocally) { if (deltaX != 0 || deltaY != 0) { Mouse.Move(deltaX, deltaY, false); } if (mouseButtons != Mouse.MouseEvents.None) { Mouse.Button(mouseButtons); } } else { if (deltaX != 0 || deltaY != 0 || mouseButtons != Mouse.MouseEvents.None) { MouseCallback(Name, deltaX, deltaY, (int)mouseButtons); } } } else { if (ws.NunchukState.C && !_previousState.NunchukState.C) { RemoteCallback(Name, "WiimoteNunchuk_Button:C"); } if (ws.NunchukState.Z && !_previousState.NunchukState.Z) { RemoteCallback(Name, "WiimoteNunchuk_Button:Z"); } } } if (ws.ExtensionType == ExtensionType.ClassicController) { if (ws.ClassicControllerState.ButtonState.A && !_previousState.ClassicControllerState.ButtonState.A) { RemoteCallback(Name, "WiimoteClassic_Button:A"); } if (ws.ClassicControllerState.ButtonState.B && !_previousState.ClassicControllerState.ButtonState.B) { RemoteCallback(Name, "WiimoteClassic_Button:B"); } if (ws.ClassicControllerState.ButtonState.Home && !_previousState.ClassicControllerState.ButtonState.Home) { RemoteCallback(Name, "WiimoteClassic_Button:Home"); } if (ws.ClassicControllerState.ButtonState.Minus && !_previousState.ClassicControllerState.ButtonState.Minus) { RemoteCallback(Name, "WiimoteClassic_Button:Minus"); } if (ws.ClassicControllerState.ButtonState.Plus && !_previousState.ClassicControllerState.ButtonState.Plus) { RemoteCallback(Name, "WiimoteClassic_Button:Plus"); } if (ws.ClassicControllerState.ButtonState.X && !_previousState.ClassicControllerState.ButtonState.X) { RemoteCallback(Name, "WiimoteClassic_Button:X"); } if (ws.ClassicControllerState.ButtonState.Y && !_previousState.ClassicControllerState.ButtonState.Y) { RemoteCallback(Name, "WiimoteClassic_Button:Y"); } if (ws.ClassicControllerState.ButtonState.TriggerL && !_previousState.ClassicControllerState.ButtonState.TriggerL) { RemoteCallback(Name, "WiimoteClassic_Button:TriggerL"); } if (ws.ClassicControllerState.ButtonState.TriggerR && !_previousState.ClassicControllerState.ButtonState.TriggerR) { RemoteCallback(Name, "WiimoteClassic_Button:TriggerR"); } if (ws.ClassicControllerState.ButtonState.ZL && !_previousState.ClassicControllerState.ButtonState.ZL) { RemoteCallback(Name, "WiimoteClassic_Button:ZL"); } if (ws.ClassicControllerState.ButtonState.ZR && !_previousState.ClassicControllerState.ButtonState.ZR) { RemoteCallback(Name, "WiimoteClassic_Button:ZR"); } if (ws.ClassicControllerState.ButtonState.Down && !_previousState.ClassicControllerState.ButtonState.Down) { RemoteCallback(Name, "WiimoteClassic_Pad:Down"); } if (ws.ClassicControllerState.ButtonState.Left && !_previousState.ClassicControllerState.ButtonState.Left) { RemoteCallback(Name, "WiimoteClassic_Pad:Left"); } if (ws.ClassicControllerState.ButtonState.Right && !_previousState.ClassicControllerState.ButtonState.Right) { RemoteCallback(Name, "WiimoteClassic_Pad:Right"); } if (ws.ClassicControllerState.ButtonState.Up && !_previousState.ClassicControllerState.ButtonState.Up) { RemoteCallback(Name, "WiimoteClassic_Pad:Up"); } } if (ws.IRState.IRSensors[0].Found && ws.IRState.IRSensors[1].Found) { int x = (int)(ScreenWidth - (ws.IRState.IRSensors[0].Position.X + ws.IRState.IRSensors[1].Position.X) / 2 * ScreenWidth); int y = (int)((ws.IRState.IRSensors[0].Position.Y + ws.IRState.IRSensors[1].Position.Y) / 2 * ScreenHeight); if (_handleMouseLocally) { Mouse.Move(x, y, true); } else { int prevX = (int)(ScreenWidth - (_previousState.IRState.IRSensors[0].Position.X + _previousState.IRState.IRSensors[1].Position.X) / 2 * ScreenWidth); int prevY = (int)((_previousState.IRState.IRSensors[0].Position.Y + _previousState.IRState.IRSensors[1].Position.Y) / 2 * ScreenHeight); int deltaX = x - prevX; int deltaY = y - prevY; MouseCallback(Name, deltaX, deltaY, 0); } } } else { _previousState = new WiimoteState(); } //_previousState.AccelCalibrationInfo.X0 = ws.AccelCalibrationInfo.X0; //_previousState.AccelCalibrationInfo.XG = ws.AccelCalibrationInfo.XG; //_previousState.AccelCalibrationInfo.Y0 = ws.AccelCalibrationInfo.Y0; //_previousState.AccelCalibrationInfo.YG = ws.AccelCalibrationInfo.YG; //_previousState.AccelCalibrationInfo.Z0 = ws.AccelCalibrationInfo.Z0; //_previousState.AccelCalibrationInfo.ZG = ws.AccelCalibrationInfo.ZG; //_previousState.AccelState.RawX = ws.AccelState.RawX; //_previousState.AccelState.RawY = ws.AccelState.RawY; //_previousState.AccelState.RawZ = ws.AccelState.RawZ; //_previousState.AccelState.X = ws.AccelState.X; //_previousState.AccelState.Y = ws.AccelState.Y; //_previousState.AccelState.Z = ws.AccelState.Z; //_previousState.Battery = ws.Battery; _previousState.ButtonState.A = ws.ButtonState.A; _previousState.ButtonState.B = ws.ButtonState.B; _previousState.ButtonState.Down = ws.ButtonState.Down; _previousState.ButtonState.Home = ws.ButtonState.Home; _previousState.ButtonState.Left = ws.ButtonState.Left; _previousState.ButtonState.Minus = ws.ButtonState.Minus; _previousState.ButtonState.One = ws.ButtonState.One; _previousState.ButtonState.Plus = ws.ButtonState.Plus; _previousState.ButtonState.Right = ws.ButtonState.Right; _previousState.ButtonState.Two = ws.ButtonState.Two; _previousState.ButtonState.Up = ws.ButtonState.Up; _previousState.Extension = ws.Extension; _previousState.ExtensionType = ws.ExtensionType; _previousState.IRState.IRSensors = ws.IRState.IRSensors; _previousState.IRState.Midpoint = ws.IRState.Midpoint; _previousState.IRState.Mode = ws.IRState.Mode; _previousState.IRState.RawMidpoint = ws.IRState.RawMidpoint; _previousState.NunchukState.C = ws.NunchukState.C; _previousState.NunchukState.Z = ws.NunchukState.Z; }