private static (short, short) GetStickValues(ref KeyboardStateSnapshot snapshot, JoyconConfigKeyboardStick <ConfigKey> stickConfig) { short stickX = 0; short stickY = 0; if (snapshot.IsPressed((Key)stickConfig.StickUp)) { stickY += 1; } if (snapshot.IsPressed((Key)stickConfig.StickDown)) { stickY -= 1; } if (snapshot.IsPressed((Key)stickConfig.StickRight)) { stickX += 1; } if (snapshot.IsPressed((Key)stickConfig.StickLeft)) { stickX -= 1; } OpenTK.Mathematics.Vector2 stick = new OpenTK.Mathematics.Vector2(stickX, stickY); stick.NormalizeFast(); return((short)(stick.X * short.MaxValue), (short)(stick.Y * short.MaxValue)); }
public GamepadStateSnapshot GetMappedStateSnapshot() { KeyboardStateSnapshot rawState = GetKeyboardStateSnapshot(); GamepadStateSnapshot result = default; lock (_userMappingLock) { if (!HasConfiguration) { return(result); } foreach (ButtonMappingEntry entry in _buttonsUserMapping) { if (entry.From == Key.Unknown || entry.From == Key.Unbound || entry.To == GamepadButtonInputId.Unbound) { continue; } // Do not touch state of button already pressed if (!result.IsPressed(entry.To)) { result.SetPressed(entry.To, rawState.IsPressed(entry.From)); } } (short leftStickX, short leftStickY) = GetStickValues(ref rawState, _configuration.LeftJoyconStick); (short rightStickX, short rightStickY) = GetStickValues(ref rawState, _configuration.RightJoyconStick); result.SetStick(StickInputId.Left, ConvertRawStickValue(leftStickX), ConvertRawStickValue(leftStickY)); result.SetStick(StickInputId.Right, ConvertRawStickValue(rightStickX), ConvertRawStickValue(rightStickY)); } return(result); }
public KeyboardInput?GetHLEKeyboardInput() { if (_gamepad is IKeyboard keyboard) { KeyboardStateSnapshot keyboardState = keyboard.GetKeyboardStateSnapshot(); KeyboardInput hidKeyboard = new KeyboardInput { Modifier = 0, Keys = new ulong[0x4] }; foreach (HLEKeyboardMappingEntry entry in KeyMapping) { ulong value = keyboardState.IsPressed(entry.TargetKey) ? 1UL : 0UL; hidKeyboard.Keys[entry.Target / 0x40] |= (value << (entry.Target % 0x40)); } foreach (HLEKeyboardMappingEntry entry in KeyModifierMapping) { int value = keyboardState.IsPressed(entry.TargetKey) ? 1 : 0; hidKeyboard.Modifier |= value << entry.Target; } return(hidKeyboard); } return(null); }
public void HandleScreenState(KeyboardStateSnapshot keyboard) { bool toggleFullscreen = keyboard.IsPressed(Key.F11) || ((keyboard.IsPressed(Key.AltLeft) || keyboard.IsPressed(Key.AltRight)) && keyboard.IsPressed(Key.Enter)) || keyboard.IsPressed(Key.Escape); bool fullScreenToggled = ParentWindow.State.HasFlag(Gdk.WindowState.Fullscreen); if (toggleFullscreen != _toggleFullscreen) { if (toggleFullscreen) { if (fullScreenToggled) { ParentWindow.Unfullscreen(); (Toplevel as MainWindow)?.ToggleExtraWidgets(true); } else { if (keyboard.IsPressed(Key.Escape)) { if (!ConfigurationState.Instance.ShowConfirmExit || GtkDialog.CreateExitDialog()) { Exit(); } } else { ParentWindow.Fullscreen(); (Toplevel as MainWindow)?.ToggleExtraWidgets(false); } } } } _toggleFullscreen = toggleFullscreen; bool toggleDockedMode = keyboard.IsPressed(Key.F9); if (toggleDockedMode != _toggleDockedMode) { if (toggleDockedMode) { ConfigurationState.Instance.System.EnableDockedMode.Value = !ConfigurationState.Instance.System.EnableDockedMode.Value; } } _toggleDockedMode = toggleDockedMode; if (_hideCursorOnIdle) { long cursorMoveDelta = Stopwatch.GetTimestamp() - _lastCursorMoveTime; Window.Cursor = (cursorMoveDelta >= CursorHideIdleTime * Stopwatch.Frequency) ? _invisibleCursor : null; } }
private bool UpdateFrame() { if (!_isActive) { return(true); } if (_isStopped) { return(false); } if (_isFocused) { Gtk.Application.Invoke(delegate { KeyboardStateSnapshot keyboard = _keyboardInterface.GetKeyboardStateSnapshot(); HandleScreenState(keyboard); if (keyboard.IsPressed(Key.Delete)) { if (!ParentWindow.State.HasFlag(WindowState.Fullscreen)) { Ptc.Continue(); } } }); } NpadManager.Update(_device.Hid, _device.TamperMachine); if (_isFocused) { KeyboardHotkeyState currentHotkeyState = GetHotkeyState(); if (currentHotkeyState.HasFlag(KeyboardHotkeyState.ToggleVSync) && !_prevHotkeyState.HasFlag(KeyboardHotkeyState.ToggleVSync)) { _device.EnableDeviceVsync = !_device.EnableDeviceVsync; } _prevHotkeyState = currentHotkeyState; } //Touchscreen bool hasTouch = false; // Get screen touch position from left mouse click // OpenTK always captures mouse events, even if out of focus, so check if window is focused. if (_isFocused && _mousePressed) { float aspectWidth = SwitchPanelHeight * ConfigurationState.Instance.Graphics.AspectRatio.Value.ToFloat(); int screenWidth = AllocatedWidth; int screenHeight = AllocatedHeight; if (AllocatedWidth > AllocatedHeight * aspectWidth / SwitchPanelHeight) { screenWidth = (int)(AllocatedHeight * aspectWidth) / SwitchPanelHeight; } else { screenHeight = (AllocatedWidth * SwitchPanelHeight) / (int)aspectWidth; } int startX = (AllocatedWidth - screenWidth) >> 1; int startY = (AllocatedHeight - screenHeight) >> 1; int endX = startX + screenWidth; int endY = startY + screenHeight; if (_mouseX >= startX && _mouseY >= startY && _mouseX < endX && _mouseY < endY) { int screenMouseX = (int)_mouseX - startX; int screenMouseY = (int)_mouseY - startY; int mX = (screenMouseX * (int)aspectWidth) / screenWidth; int mY = (screenMouseY * SwitchPanelHeight) / screenHeight; TouchPoint currentPoint = new TouchPoint { X = (uint)mX, Y = (uint)mY, // Placeholder values till more data is acquired DiameterX = 10, DiameterY = 10, Angle = 90 }; hasTouch = true; _device.Hid.Touchscreen.Update(currentPoint); } } if (!hasTouch) { _device.Hid.Touchscreen.Update(); } _device.Hid.DebugPad.Update(); return(true); }
private bool UpdateFrame() { if (!_isActive) { return(true); } if (_isStopped) { return(false); } if ((Toplevel as MainWindow).IsFocused) { Application.Invoke(delegate { KeyboardStateSnapshot keyboard = _keyboardInterface.GetKeyboardStateSnapshot(); HandleScreenState(keyboard); if (keyboard.IsPressed(Key.Delete)) { if (!ParentWindow.State.HasFlag(WindowState.Fullscreen)) { Ptc.Continue(); } } }); } NpadManager.Update(ConfigurationState.Instance.Graphics.AspectRatio.Value.ToFloat()); if ((Toplevel as MainWindow).IsFocused) { KeyboardHotkeyState currentHotkeyState = GetHotkeyState(); if (currentHotkeyState.HasFlag(KeyboardHotkeyState.ToggleVSync) && !_prevHotkeyState.HasFlag(KeyboardHotkeyState.ToggleVSync)) { Device.EnableDeviceVsync = !Device.EnableDeviceVsync; } if ((currentHotkeyState.HasFlag(KeyboardHotkeyState.Screenshot) && !_prevHotkeyState.HasFlag(KeyboardHotkeyState.Screenshot)) || ScreenshotRequested) { ScreenshotRequested = false; Renderer.Screenshot(); } _prevHotkeyState = currentHotkeyState; } // Touchscreen bool hasTouch = false; // Get screen touch position if ((Toplevel as MainWindow).IsFocused && !ConfigurationState.Instance.Hid.EnableMouse) { hasTouch = TouchScreenManager.Update(true, (_inputManager.MouseDriver as GTK3MouseDriver).IsButtonPressed(MouseButton.Button1), ConfigurationState.Instance.Graphics.AspectRatio.Value.ToFloat()); } if (!hasTouch) { TouchScreenManager.Update(false); } Device.Hid.DebugPad.Update(); return(true); }
public void ReadInput() { _keyboardState = _keyboard.GetKeyboardStateSnapshot(); }