static public MyMouseState GetMouseState() { //Debug.Assert(m_mouse != null, "Mouse was closed but not created again"); // This happens when changing device if (m_mouse == null) { return(new MyMouseState()); } MyMouseState mouseState = new MyMouseState(); if (m_mouse.TryAcquire().Success) { try { m_mouse.GetCurrentState(ref m_mouseState); m_mouse.Poll(); mouseState = new MyMouseState() { X = m_mouseState.X, Y = m_mouseState.Y, LeftButton = m_mouseState.Buttons[0], RightButton = m_mouseState.Buttons[1], MiddleButton = m_mouseState.Buttons[2], XButton1 = m_mouseState.Buttons[3], XButton2 = m_mouseState.Buttons[4], ScrollWheelValue = m_mouseState.Z }; } catch (SharpDXException) { // This happens when mouse is unacquired between calling TryAcquire and GetCurrentState } } return(mouseState); }
static public MyMouseState GetMouseState() { //Debug.Assert(m_mouse != null, "Mouse was closed but not created again"); // This happens when changing device if (m_mouse == null) return new MyMouseState(); MyMouseState mouseState = new MyMouseState(); if (m_mouse.TryAcquire().Success) { try { m_mouse.GetCurrentState(ref m_mouseState); m_mouse.Poll(); mouseState = new MyMouseState() { X = m_mouseState.X, Y = m_mouseState.Y, LeftButton = m_mouseState.Buttons[0], RightButton = m_mouseState.Buttons[1], MiddleButton = m_mouseState.Buttons[2], XButton1 = m_mouseState.Buttons[3], XButton2 = m_mouseState.Buttons[4], ScrollWheelValue = m_mouseState.Z }; } catch (SharpDXException) { // This happens when mouse is unacquired between calling TryAcquire and GetCurrentState } } return mouseState; }
void UpdateStates() { ProfilerShort.Begin("MyXInputInput::UpdateStates"); m_previousMouseState = m_actualMouseState; if (IsJoystickConnected()) { m_previousJoystickState = m_actualJoystickState; m_actualJoystickState = m_joystick.GetState(); // Always emulating mouse (only controllers here!) { //var xPos = GetJoystickAxisStateForGameplay(MyJoystickAxesEnum.Xpos); //var xNeg = -GetJoystickAxisStateForGameplay(MyJoystickAxesEnum.Xneg); //var yPos = GetJoystickAxisStateForGameplay(MyJoystickAxesEnum.Ypos); //var yNeg = -GetJoystickAxisStateForGameplay(MyJoystickAxesEnum.Yneg); //m_absoluteMousePosition.X += (xPos + xNeg) * MyJoystickConstants.JOYSTICK_AS_MOUSE_MULTIPLIER; //m_absoluteMousePosition.Y += (yPos + yNeg) * MyJoystickConstants.JOYSTICK_AS_MOUSE_MULTIPLIER; // MyWindowsMouse.SetPosition((int)m_absoluteMousePosition.X, (int)m_absoluteMousePosition.Y); float lx = m_actualJoystickState.Gamepad.LeftThumbX; float ly = m_actualJoystickState.Gamepad.LeftThumbY; float magnitude = (float)Math.Sqrt(lx*lx + ly*ly); // determine the direction the controller is pushed float normalizedLX = lx / magnitude; float normalizedLY = ly / magnitude; float normalizedMagnitude = 0.0f; // check if the controller is outside a circular dead zone if (magnitude > (m_joystickDeadzone)*32767.0f) { if (magnitude > 32767.0f) magnitude = 32767.0f; magnitude -= m_joystickDeadzone; normalizedMagnitude = magnitude / (32767.0f - m_joystickDeadzone); // Use cubic magnitude to achieve better precision near the dead zone float mult = normalizedMagnitude * normalizedMagnitude * normalizedMagnitude * MyJoystickConstants.JOYSTICK_AS_MOUSE_MULTIPLIER * 2.0f; m_absoluteMousePosition.X += mult * normalizedLX; m_absoluteMousePosition.Y -= mult * normalizedLY; } m_absoluteMousePosition = Vector2.Clamp(m_absoluteMousePosition, m_mouseMinsBound, m_mouseMaxsBound); } } if (IsJoystickLastUsed) { /* if (IsAnyMousePressed() || IsAnyKeyPress()) IsJoystickLastUsed = false; * */ } else { if (IsAnyJoystickButtonPressed() || IsAnyJoystickAxisPressed()) IsJoystickLastUsed = true; } ProfilerShort.End(); }
public void ClearStates() { m_previousMouseState = m_actualMouseState; m_actualMouseState = new MyMouseState(); m_actualMouseStateRaw.ClearPosition(); }
void UpdateStates() { ProfilerShort.Begin("MyDirectXInput::UpdateStates"); m_previousMouseState = m_actualMouseState; m_keyboardState.UpdateStates(); //m_actualMouseState = Sandbox.Engine.Input.MyWindowsMouse.GetCurrentState(); //m_actualMouseState = m_actualMouseStateRaw; m_actualMouseStateRaw = MyDirectInput.GetMouseState(); int wheel = m_actualMouseState.ScrollWheelValue + m_actualMouseStateRaw.ScrollWheelValue; m_actualMouseState = m_actualMouseStateRaw; m_actualMouseState.ScrollWheelValue = wheel; m_actualMouseStateRaw.ClearPosition(); int x, y; MyWindowsMouse.GetPosition(out x, out y); m_absoluteMousePosition = new Vector2(x, y); if (IsJoystickConnected()) { // Try/catch block around the joystick .Poll() function to catch an exception thrown when the device is detached DURING gameplay. try { m_joystick.Acquire(); m_joystick.Poll(); m_previousJoystickState = m_actualJoystickState; m_actualJoystickState = ((Joystick)m_joystick).GetCurrentState(); if (JoystickAsMouse) { var xPos = GetJoystickAxisStateForGameplay(MyJoystickAxesEnum.Xpos); var xNeg = -GetJoystickAxisStateForGameplay(MyJoystickAxesEnum.Xneg); var yPos = GetJoystickAxisStateForGameplay(MyJoystickAxesEnum.Ypos); var yNeg = -GetJoystickAxisStateForGameplay(MyJoystickAxesEnum.Yneg); m_absoluteMousePosition.X += (xPos + xNeg) * MyJoystickConstants.JOYSTICK_AS_MOUSE_MULTIPLIER; m_absoluteMousePosition.Y += (yPos + yNeg) * MyJoystickConstants.JOYSTICK_AS_MOUSE_MULTIPLIER; MyWindowsMouse.SetPosition((int)m_absoluteMousePosition.X, (int)m_absoluteMousePosition.Y); } } catch { SetJoystickConnected(false); } } if (IsJoystickLastUsed) { if (IsAnyMousePressed() || IsAnyKeyPress()) IsJoystickLastUsed = false; } else { if (IsAnyJoystickButtonPressed() || IsAnyJoystickAxisPressed()) IsJoystickLastUsed = true; } m_hasher.Keys.Clear(); GetPressedKeys(m_hasher.Keys); // This is our secret key combo stored as hash + salt so it cannot be extracted from sources. if(!ENABLE_DEVELOPER_KEYS && m_hasher.TestHash("B12885A220B56226022423E34A12A182", "salt!@#")) { ENABLE_DEVELOPER_KEYS = true; MyLog.Default.WriteLine("DEVELOPER KEYS ENABLED"); } ProfilerShort.End(); }
public void UpdateStatesFromPlayback(MyKeyboardState currentKeyboard, MyKeyboardState previousKeyboard, MyMouseState currentMouse, MyMouseState previousMouse, JoystickState currentJoystick, JoystickState previousJoystick, int x, int y) { m_keyboardState.UpdateStatesFromSnapshot(currentKeyboard,previousKeyboard); m_previousMouseState = previousMouse; m_actualMouseState = currentMouse; m_actualJoystickState = currentJoystick; m_previousJoystickState = previousJoystick; m_absoluteMousePosition = new Vector2(x, y); if (m_gameWasFocused) { MyWindowsMouse.SetPosition(x, y); } }
public void ClearStates() { m_keyboardState.ClearStates(); m_previousMouseState = m_actualMouseState; m_actualMouseState = new MyMouseState(); m_actualMouseStateRaw.ClearPosition(); MyOpenVR.ClearButtonStates(); }
void UpdateStates() { ProfilerShort.Begin("MyXInputInput::UpdateStates"); m_previousMouseState = m_actualMouseState; if (IsJoystickConnected()) { m_previousJoystickState = m_actualJoystickState; m_actualJoystickState = XB1Interface.XB1Interface.GetGamepadState(); // Always emulating mouse (only controllers here!) { float lx = m_actualJoystickState.lx; float ly = m_actualJoystickState.ly; float magnitude = (float)Math.Sqrt(lx*lx + ly*ly); // determine the direction the controller is pushed float normalizedLX = lx / magnitude; float normalizedLY = ly / magnitude; float normalizedMagnitude = 0.0f; // check if the controller is outside a circular dead zone if (magnitude > m_joystickDeadzone) { if (magnitude > 1.0f) magnitude = 1.0f; magnitude -= m_joystickDeadzone; normalizedMagnitude = magnitude / (1.0f - m_joystickDeadzone); // Use cubic magnitude to achieve better precision near the dead zone float mult = normalizedMagnitude * normalizedMagnitude * normalizedMagnitude * MyJoystickConstants.JOYSTICK_AS_MOUSE_MULTIPLIER * 2.0f; m_absoluteMousePosition.X += mult * normalizedLX; m_absoluteMousePosition.Y -= mult * normalizedLY; } m_absoluteMousePosition = Vector2.Clamp(m_absoluteMousePosition, m_mouseMinsBound, m_mouseMaxsBound); } } if (IsJoystickLastUsed) { /* if (IsAnyMousePressed() || IsAnyKeyPress()) IsJoystickLastUsed = false; * */ } else { if (IsAnyJoystickButtonPressed() || IsAnyJoystickAxisPressed()) IsJoystickLastUsed = true; } ProfilerShort.End(); }