23 lines
No EOL
567 B
C#
23 lines
No EOL
567 B
C#
namespace Domain.Input {
|
|
public abstract class InputReader {
|
|
private bool _wasPressed;
|
|
private bool _isPressed;
|
|
|
|
protected abstract int Key { get; }
|
|
|
|
public void UpdateInput() {
|
|
_wasPressed = _isPressed;
|
|
short keyState = Win32API.GetAsyncKeyState(Key);
|
|
|
|
if (_wasPressed && keyState == 0) {
|
|
_isPressed = false;
|
|
}else if (!_isPressed && keyState != 0) {
|
|
_isPressed = true;
|
|
}
|
|
}
|
|
|
|
public bool KeyDown() => _isPressed && !_wasPressed;
|
|
public bool KeyPressed() => _isPressed;
|
|
public bool KeyUp() => !_isPressed && _wasPressed;
|
|
}
|
|
} |