feat: key history algorithm

This commit is contained in:
Gerard Gascón 2024-04-14 20:02:15 +02:00
parent 5d2da3ddbf
commit 1869a92580
8 changed files with 115 additions and 10 deletions

View file

@ -1,17 +1,15 @@
namespace Domain.Input {
public abstract class InputReader {
private bool _wasPressed;
private bool _isPressed;
protected bool WasPressed;
protected bool IsPressed;
protected abstract int Key { get; }
public void UpdateInput() {
_wasPressed = _isPressed;
_isPressed = Win32API.GetAsyncKeyState(Key) != 0;
public virtual void UpdateInput() {
WasPressed = IsPressed;
IsPressed = Win32API.GetAsyncKeyState(Key) != 0;
}
public bool KeyDown() => _isPressed && !_wasPressed;
public bool KeyPressed() => _isPressed;
public bool KeyUp() => !_isPressed && _wasPressed;
public bool KeyDown() => IsPressed && !WasPressed;
}
}