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)); } }
void MainWindow_KeyDown(object sender, KeyEventArgs e) { lock (KeyboardState) { if (!KeyboardState.Contains(e.Key)) { KeyboardState.Add(e.Key); } } }
private void CheckKeyState() { lock (KeyboardState) { PreviousKeyboardState.Clear(); foreach (var key in KeyboardState) { PreviousKeyboardState.Add(key); } } }