public static void Poll() { KeyboardState kstate = keyboard.GetCurrentState(); foreach (Key k in kstate.AllKeys) { if (kstate.IsPressed(k)) { keyStates[k] = true; } if (kstate.IsReleased(k)) { keyStates[k] = false; } } MouseState mState = mouseRel.GetCurrentState(); LMBPressed = mState.GetButtons()[0]; RMBPressed = mState.GetButtons()[1]; MMBPressed = mState.GetButtons()[2]; mouseDeltaPos = new Vector3(mState.X, mState.Y, mState.Z); mouseAbsPosNormalized.X = (Renderer.viewport.PointToClient(System.Windows.Forms.Control.MousePosition).X - (Renderer.viewport.Width / 2F)) / (float)Renderer.viewport.Width; mouseAbsPosNormalized.Y = (Renderer.viewport.PointToClient(System.Windows.Forms.Control.MousePosition).Y - (Renderer.viewport.Height / 2F)) / (float)Renderer.viewport.Height; mouseAbsPosScreen.X = Renderer.viewport.PointToClient(System.Windows.Forms.Control.MousePosition).X; mouseAbsPosScreen.Y = Renderer.viewport.PointToClient(System.Windows.Forms.Control.MousePosition).Y; }
/// <summary> /// Makes the new mouse state mirror the previous mouse state (thus freezing mouse input) /// </summary> private void mirrorOldMouseState() { // The cursor is not on the window, or the window does not have focus // Disable all NEW mouse presses var left = mouseState.GetButtons()[0]; var right = mouseState.GetButtons()[1]; var prevLeft = prevMouseState.GetButtons()[0]; var prevRight = prevMouseState.GetButtons()[1]; if (prevLeft == false) { left = false; } if (prevRight == false) { right = false; } //TODO: /*mouseState = new MouseState(mouseState.X, mouseState.Y, mouseState.ScrollWheelValue, * left, mouseState.MiddleButton, right, * mouseState.XButton1, mouseState.XButton2);*/ }
//Creates and returns event data to send to the controls if the mouse has been clicked. //Returns null if it hasn't. private DXMouseEventArgs GetClickEventData(MouseState newMouseState) { bool[] oldButtonData = this.previousMouseState.GetButtons(); bool[] newButtonData = newMouseState.GetButtons(); MouseAction action = MouseAction.None; int buttonIndex = 0; for (int i = 0; i < oldButtonData.Length; i++) { if (oldButtonData[i] != newButtonData[i]) { buttonIndex = i; if (oldButtonData[i]) { action = MouseAction.Release; } else { action = MouseAction.Click; } break; } } if (action == MouseAction.None) { return(null); } else { return(new DXMouseEventArgs( action, newMouseState, Control.MousePosition, buttonIndex, this)); } }
private void HandleMouse() { if (mouse.Acquire().IsFailure) { return; } if (mouse.Poll().IsFailure) { return; } try { mouse.GetCurrentState(ref mouseState); bool[] buttons = mouseState.GetButtons(); for (int i = 0; i < buttons.Length && i < 5; i++) { if (buttons[i] != currentMouseButtons[i]) { switch (i) { case 0: InputEvent(EmuKeys.Mouse1, buttons[i]); break; case 1: InputEvent(EmuKeys.Mouse2, buttons[i]); break; case 2: InputEvent(EmuKeys.Mouse3, buttons[i]); break; case 3: InputEvent(EmuKeys.Mouse4, buttons[i]); break; case 4: InputEvent(EmuKeys.Mouse5, buttons[i]); break; } currentMouseButtons[i] = buttons[i]; } } int newMouseX = Cursor.Position.X; //Not even going to bother with attempting to use crazy relative Direct Input mouse data int newMouseY = Cursor.Position.Y; if (newMouseX != mouseX) { InputScalerEvent(EmuKeys.MouseX, newMouseX); } if (newMouseY != mouseY) { InputScalerEvent(EmuKeys.MouseY, newMouseY); } mouseX = newMouseX; mouseY = newMouseY; } catch { mouse.Acquire(); } }
public void tポーリング(bool bWindowがアクティブ中, bool bバッファ入力を使用する) { for (int i = 0; i < 8; i++) { this.bMousePushDown[i] = false; this.bMousePullUp[i] = false; } if (((bWindowがアクティブ中 && (this.devMouse != null)) && !this.devMouse.Acquire().IsFailure) && !this.devMouse.Poll().IsFailure) { // this.list入力イベント = new List<STInputEvent>( 32 ); this.list入力イベント.Clear(); // #xxxxx 2012.6.11 yyagi; To optimize, I removed new(); if (bバッファ入力を使用する) { #region [ a.バッファ入力 ] //----------------------------- var bufferedData = this.devMouse.GetBufferedData(); if (Result.Last.IsSuccess && bufferedData != null) { foreach (MouseState data in bufferedData) { for (int k = 0; k < 8; k++) { if (data.IsPressed(k)) { STInputEvent item = new STInputEvent() { nKey = k, b押された = true, b離された = false, nTimeStamp = CSound管理.rc演奏用タイマ.nサウンドタイマーのシステム時刻msへの変換(data.TimeStamp), nVelocity = CInput管理.n通常音量 }; this.list入力イベント.Add(item); this.bMouseState[k] = true; this.bMousePushDown[k] = true; } else if (data.IsReleased(k)) { STInputEvent item = new STInputEvent() { nKey = k, b押された = false, b離された = true, nTimeStamp = CSound管理.rc演奏用タイマ.nサウンドタイマーのシステム時刻msへの変換(data.TimeStamp), nVelocity = CInput管理.n通常音量 }; this.list入力イベント.Add(item); this.bMouseState[k] = false; this.bMousePullUp[k] = true; } } } } //----------------------------- #endregion } else { #region [ b.状態入力 ] //----------------------------- MouseState currentState = this.devMouse.GetCurrentState(); if (Result.Last.IsSuccess && currentState != null) { bool[] buttons = currentState.GetButtons(); for (int j = 0; (j < buttons.Length) && (j < 8); j++) { if (this.bMouseState[j] == false && buttons[j] == true) { var ev = new STInputEvent() { nKey = j, b押された = true, b離された = false, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 nVelocity = CInput管理.n通常音量, }; this.list入力イベント.Add(ev); this.bMouseState[j] = true; this.bMousePushDown[j] = true; } else if (this.bMouseState[j] == true && buttons[j] == false) { var ev = new STInputEvent() { nKey = j, b押された = false, b離された = true, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 nVelocity = CInput管理.n通常音量, }; this.list入力イベント.Add(ev); this.bMouseState[j] = false; this.bMousePullUp[j] = true; } } } //----------------------------- #endregion } } }
public void tポーリング(bool bWindowがアクティブ中, bool bバッファ入力を使用する) { for (int i = 0; i < 8; i++) { this.bMousePushDown[i] = false; this.bMousePullUp[i] = false; } if (((bWindowがアクティブ中 && (this.devMouse != null)) && !this.devMouse.Acquire().IsFailure) && !this.devMouse.Poll().IsFailure) { // this.list入力イベント = new List<STInputEvent>( 32 ); this.list入力イベント.Clear(); // #xxxxx 2012.6.11 yyagi; To optimize, I removed new(); if (bバッファ入力を使用する) { #region [ a.バッファ入力 ] //----------------------------- var length = this.devMouse.GetDeviceData(_rawBufferedDataArray, false); if (!Result.Last.IsSuccess) { return; } for (int i = 0; i < length; i++) { var rawBufferedData = _rawBufferedDataArray[i]; var key = rawBufferedData.Offset - 12; var wasPressed = (rawBufferedData.Data & 128) == 128; if (!(-1 < key && key < 8)) { continue; } STInputEvent item = new STInputEvent() { nKey = key, b押された = wasPressed, nTimeStamp = CSound管理.rc演奏用タイマ.nサウンドタイマーのシステム時刻msへの変換(rawBufferedData.Timestamp), }; this.list入力イベント.Add(item); this.bMouseState[item.nKey] = wasPressed; this.bMousePushDown[item.nKey] = wasPressed; this.bMousePullUp[item.nKey] = !wasPressed; } //----------------------------- #endregion } else { #region [ b.状態入力 ] //----------------------------- MouseState currentState = this.devMouse.GetCurrentState(); if (Result.Last.IsSuccess && currentState != null) { bool[] buttons = currentState.GetButtons(); for (int j = 0; (j < buttons.Length) && (j < 8); j++) { if (this.bMouseState[j] == false && buttons[j] == true) { var ev = new STInputEvent() { nKey = j, b押された = true, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 }; this.list入力イベント.Add(ev); this.bMouseState[j] = true; this.bMousePushDown[j] = true; } else if (this.bMouseState[j] == true && buttons[j] == false) { var ev = new STInputEvent() { nKey = j, b押された = false, nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻, // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。 }; this.list入力イベント.Add(ev); this.bMouseState[j] = false; this.bMousePullUp[j] = true; } } } //----------------------------- #endregion } } }