private void wm_WiiMoteChanged(object sender, WiiMoteChangedEventArgs args) { if (!_Active) { return; } WiiMoteStatus ws = args.WiiMoteState; Point p = ws.IRState.Position; p.X = 1023 - p.X; //key events bool alt = false; bool shift = false; bool ctrl = false; bool pressed = false; char unicode = char.MinValue; EGesture gesture = _Gesture.GetGesture(p); bool lb = false; bool rb = gesture == EGesture.Back; Keys key = Keys.None; if (ws.ButtonState.A && !_ButtonStates[0]) { lb = true; } else if (ws.ButtonState.B && !_ButtonStates[1]) { _Gesture.SetLockPosition(p); } else if (!ws.ButtonState.B && _ButtonStates[1]) { _Gesture.Reset(); } else if (ws.ButtonState.Down && !_ButtonStates[2]) { key = Keys.Right; } else if (ws.ButtonState.Up && !_ButtonStates[3]) { key = Keys.Left; } else if (ws.ButtonState.Left && !_ButtonStates[4]) { key = Keys.Down; } else if (ws.ButtonState.Right && !_ButtonStates[5]) { key = Keys.Up; } else if (ws.ButtonState.Home && !_ButtonStates[6]) { key = Keys.Space; } else if (ws.ButtonState.Minus && !_ButtonStates[7]) { key = Keys.PageDown; } else if (ws.ButtonState.Plus && !_ButtonStates[8]) { key = Keys.PageUp; } else if (ws.ButtonState.One && !_ButtonStates[9]) { key = Keys.Enter; } else if (ws.ButtonState.Two && !_ButtonStates[10]) { key = Keys.Escape; } _ButtonStates[0] = ws.ButtonState.A; _ButtonStates[1] = ws.ButtonState.B; _ButtonStates[2] = ws.ButtonState.Down; _ButtonStates[3] = ws.ButtonState.Up; _ButtonStates[4] = ws.ButtonState.Left; _ButtonStates[5] = ws.ButtonState.Right; _ButtonStates[6] = ws.ButtonState.Home; _ButtonStates[7] = ws.ButtonState.Minus; _ButtonStates[8] = ws.ButtonState.Plus; _ButtonStates[9] = ws.ButtonState.One; _ButtonStates[10] = ws.ButtonState.Two; if (alt || shift || ctrl || pressed || unicode != char.MinValue || key != Keys.None) { KeyEvent pool = new KeyEvent(ESender.WiiMote, alt, shift, ctrl, pressed, unicode, key); lock (_KeyCopyLock) { _KeysPool.Add(pool); } } //mouse events float reducing = 0.15f; float factor = 1f / (1f - reducing * 2f); float rx = (((float)p.X / 1024f) - reducing) * factor; float ry = (((float)p.Y / 768f) - reducing) * factor; int x = (int)(rx * (float)CSettings.iRenderW); int y = (int)(ry * (float)CSettings.iRenderH); bool ld = false; bool lbh = !lb && ws.ButtonState.A; bool rbh = false; bool mb = false; bool mbh = false; int wheel = 0; if (gesture == EGesture.ScrollUp) { wheel = -1; } if (gesture == EGesture.ScrollDown) { wheel = 1; } MouseEvent mpool = new MouseEvent(); bool trigger = false; if (!lb && !rb && (p.X != _OldPosition.X || p.Y != _OldPosition.Y)) { mpool = new MouseEvent(ESender.WiiMote, alt, shift, ctrl, x, y, false, false, false, wheel, lbh, rbh, false, mbh); trigger = true; } else if (lb || rb) { mpool = new MouseEvent(ESender.WiiMote, alt, shift, ctrl, x, y, lb, ld, rb, wheel, false, false, mb, false); trigger = true; } if (trigger) { lock (_MouseCopyLock) { _MousePool.Add(mpool); } } _OldPosition.X = p.X; _OldPosition.Y = p.Y; }
public WiiMoteChangedEventArgs(WiiMoteStatus ws) { WiiMoteState = ws; }