public void Update(GameEngine engine) { //Console.WriteLine(DeltaScrollWheel); //DeltaScrollWheel = 0; //we only want the difference for each frame, the total value is irrelevant PreviousKeyboardState.Clear(); PreviousMouseState.Clear(); PreviousMousePosition = MousePosition; MousePosition = Mouse.GetPosition(engine.Window); foreach (KeyValuePair <Keyboard.Key, bool> valuePair in KeyboardState) { PreviousKeyboardState.Add(valuePair.Key, valuePair.Value); } foreach (KeyValuePair <Mouse.Button, bool> valuePair in MouseState) { PreviousMouseState.Add(valuePair.Key, valuePair.Value); } KeyboardState.Clear(); MouseState.Clear(); foreach (Keyboard.Key key in keysEnum) { KeyboardState.Add(key, CheckKey(key)); } foreach (Mouse.Button button in buttonsEnum) { MouseState.Add(button, CheckButton(button)); } }
private void CheckKeyState() { lock (KeyboardState) { PreviousKeyboardState.Clear(); foreach (var key in KeyboardState) { PreviousKeyboardState.Add(key); } } }
bool IVirtualKeyboard.TryGetText(uint virtualKey, VirtualKeyModifiers virtualKeyModifiers, out string text, out bool isDeadKey) { try { if (VirtualKeyModifiers.Oem1 == (virtualKeyModifiers & VirtualKeyModifiers.Oem1)) { if (!Oem1Modifier.HasValue) { text = String.Empty; isDeadKey = false; return(false); } } if (Oem1Modifier.HasValue && KeyboardState.IsKeySet(Oem1Modifier.Value)) { virtualKeyModifiers |= VirtualKeyModifiers.Oem1; } if (VirtualKeyModifiers.Oem2 == (virtualKeyModifiers & VirtualKeyModifiers.Oem2)) { if (!Oem2Modifier.HasValue) { text = String.Empty; isDeadKey = false; return(false); } } if (Oem2Modifier.HasValue && KeyboardState.IsKeySet(Oem2Modifier.Value)) { virtualKeyModifiers |= VirtualKeyModifiers.Oem2; } var key = KeyInterop.KeyFromVirtualKey((int)virtualKey); var keyState = new KeyState(key, virtualKeyModifiers); isDeadKey = false; return(_keyMap.TryGetValue(keyState, out text)); } finally { _keyboardState.Clear(); } }