private void handleKeyboardEvent(object sender, KeyboardKeyEventArgs e) { var rawState = e.Keyboard; if (lastRawState != null && rawState.Equals(lastRawState)) { return; } lastRawState = rawState; var newState = new TkKeyboardState(rawState); PendingInputs.Enqueue(new KeyboardKeyInput(newState.Keys, lastEventState?.Keys)); lastEventState = newState; FrameStatistics.Increment(StatisticsCounterType.KeyEvents); }
public override bool Initialize(GameHost host) { Enabled.BindValueChanged(e => { if (e.NewValue) { host.Window.KeyDown += handleKeyboardEvent; host.Window.KeyUp += handleKeyboardEvent; } else { host.Window.KeyDown -= handleKeyboardEvent; host.Window.KeyUp -= handleKeyboardEvent; lastRawState = null; lastEventState = null; } }, true); return(true); }
public override bool Initialize(GameHost host) { Enabled.ValueChanged += enabled => { if (enabled) { host.Window.KeyDown += handleKeyboardEvent; host.Window.KeyUp += handleKeyboardEvent; } else { host.Window.KeyDown -= handleKeyboardEvent; host.Window.KeyUp -= handleKeyboardEvent; lastRawState = null; lastEventState = null; } }; Enabled.TriggerChange(); return(true); }