/// <summary> /// This function houses a hack to fix the window missing some input events, /// see Stride pull #181 for more information (https://github.com/stride3d/stride/pull/181). /// TODO: Find a proper solution to replace this workaround. /// </summary> private void MissingInputHack() { #if STRIDE_INPUT_RAWINPUT Device.RegisterDevice(SharpDX.Multimedia.UsagePage.Generic, SharpDX.Multimedia.UsageId.GenericKeyboard, DeviceFlags.None); Device.KeyboardInput += (sender, args) => { switch (args.State) { case KeyState.SystemKeyDown: case KeyState.ImeKeyDown: case KeyState.KeyDown: { keyboard?.HandleKeyUp(args.Key); heldKeys.Add(args.Key); break; } case KeyState.SystemKeyUp: case KeyState.ImeKeyUp: case KeyState.KeyUp: { heldKeys.Remove(args.Key); keyboard?.HandleKeyDown(args.Key); break; } } }; #endif }
private void UIControlOnLostFocus(object sender, EventArgs eventArgs) { // Release keys/buttons when control focus is lost (this prevents some keys getting stuck when a focus loss happens when moving the camera) if (keyboard != null) { foreach (var key in keyboard.KeyRepeats.Keys.ToArray()) { keyboard.HandleKeyUp(key); } } mouse?.ForceReleaseButtons(); }
public override void Update() { // This check handles the case where the game window focus changes during key events causing it to drop WM_KEYUP events if (heldKeys.Count > 0) { foreach (var key in heldKeys) { if ((Win32Native.GetKeyState((int)key) & 0x8000) == 0) { keysToRelease.Add(key); } } foreach (var keyToRelease in keysToRelease) { keyboard?.HandleKeyUp(keyToRelease); heldKeys.Remove(keyToRelease); } keysToRelease.Clear(); } }