feat: key history algorithm
This commit is contained in:
parent
5d2da3ddbf
commit
1869a92580
8 changed files with 115 additions and 10 deletions
57
Assets/Scripts/Domain/Input/GeminadaReader.cs
Normal file
57
Assets/Scripts/Domain/Input/GeminadaReader.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Domain.Input {
|
||||
public class GeminadaReader : InputReader {
|
||||
protected override int Key { get; } = 0x33;
|
||||
private int LKey { get; } = 76;
|
||||
|
||||
private bool _lPressed;
|
||||
private bool _lWasPressed;
|
||||
private bool _dotPressed;
|
||||
private bool _dotWasPressed;
|
||||
|
||||
private List<int> _lastPresses;
|
||||
|
||||
public override void UpdateInput() {
|
||||
if (UpdateLInput()) {
|
||||
if (_lastPresses.Count == 0) {
|
||||
_lastPresses.Add(LKey);
|
||||
} else if (_lastPresses.Count >= 2) {
|
||||
if (_lastPresses[^1] == Key && _lastPresses[^2] == LKey) {
|
||||
IsPressed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
UpdateDotInput();
|
||||
}
|
||||
|
||||
private bool UpdateDotInput() {
|
||||
_dotWasPressed = _dotPressed;
|
||||
short dotState = Win32API.GetAsyncKeyState(Key);
|
||||
|
||||
if (!_dotWasPressed && dotState != 0) {
|
||||
_dotPressed = true;
|
||||
return true;
|
||||
}
|
||||
if (_dotPressed && dotState == 0) {
|
||||
_dotPressed = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool UpdateLInput() {
|
||||
_lWasPressed = _lPressed;
|
||||
short lState = Win32API.GetAsyncKeyState(LKey);
|
||||
|
||||
if (!_lWasPressed && lState != 0) {
|
||||
_lPressed = true;
|
||||
return true;
|
||||
}
|
||||
if (_lPressed && lState == 0) {
|
||||
_lPressed = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue