/// <inheritdoc /> protected override bool UpdatePlatform() { // Shift keys on windows tend to "stick" // When one key is held, the other doesn't receive down events, and an up event // is sent only to the latter one. To work around this manually query the status of both shift keys every tick. if (IsFocused) { KeyState lShift = User32.GetAsyncKeyState(VirtualKey.LSHIFT); UpdateKeyStatus(Key.LeftShift, lShift.IsPressed); KeyState rShift = User32.GetAsyncKeyState(VirtualKey.RSHIFT); UpdateKeyStatus(Key.RightShift, rShift.IsPressed); } while (User32.PeekMessage(out Message msg, IntPtr.Zero, 0, 0, PeekMessageFlags.PM_REMOVE)) { // Generated by task manager and stuff like that. // The WM_QUIT message is not associated with a window and therefore will never be received through a window's window procedure. if (msg.Value == WM.QUIT) { IsOpen = false; return(false); } User32.TranslateMessage(ref msg); User32.DispatchMessage(ref msg); } if (HostPaused) { User32.WaitMessage(); } return(true); }
/// <inheritdoc /> protected override bool UpdatePlatform() { // Update input. // NOTE: Shift keys on Windows tend to "stick" when both are pressed as // no key up message is generated by the first key release // The other half of this is in the handling of WM_KEYUP // HACK: Query actual key state and synthesize release events as needed KeyState lShift = User32.GetAsyncKeyState(VirtualKey.LSHIFT); KeyState rShift = User32.GetAsyncKeyState(VirtualKey.RSHIFT); // Check if it was down, but no longer is. if (_keys[(short)Key.LeftShift] && lShift.Value != 0) { UpdateKeyStatus(Key.LeftShift, false); } if (_keys[(short)Key.RightShift] && rShift.Value != 0) { UpdateKeyStatus(Key.RightShift, false); } while (User32.PeekMessage(out Message msg, IntPtr.Zero, 0, 0, PeekMessageFlags.PM_REMOVE)) { // Things like the task manager will generate this message. if (msg.Value == WM.QUIT) { IsOpen = false; return(false); } User32.TranslateMessage(ref msg); User32.DispatchMessage(ref msg); } // Check if focused. if (!IsFocused && !Engine.Configuration.DebugMode) { User32.WaitMessage(); } return(true); }