Skip to content

Commit f2b4212

Browse files
committed
Update Lab's InputTest to also test polling scancodes
1 parent 88294d2 commit f2b4212

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/Lab/Experiments/InputTest/Program.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ private static void Run(string[]? args = null)
3636

3737
static Key[] _allKeys = Enum.GetValues(typeof(Key)).Cast<Key>().Where(x => x != Key.Unknown).ToArray();
3838
static List<Key> _keysDown = new List<Key>();
39+
static List<int> _scancodesDown = new List<int>();
3940

4041
public static Action OnLoad(IView window) =>
4142
() =>
@@ -86,6 +87,14 @@ public static Action<double> OnUpdate(IInputContext input) =>
8687
Console.WriteLine($"[ERROR] IsKeyPressed() and event mismatch! Key {k}");
8788
}
8889
}
90+
91+
for (int s = 0; s < 256; s++)
92+
{
93+
if (_scancodesDown.Contains(s) != input.Keyboards.Any(x => x.IsScancodePressed(s)))
94+
{
95+
Console.WriteLine($"[ERROR] IsScancodePressed() and event mismatch! Scancode {s}");
96+
}
97+
}
8998
};
9099

91100
private static void GamepadOnTriggerMoved(IGamepad gamepad, Trigger trigger)
@@ -274,12 +283,18 @@ private static void KeyboardOnKeyUp(IKeyboard keyboard, Key key, int scancode)
274283

275284
if (key != Key.Unknown)
276285
{
277-
int index = _keysDown.IndexOf(key);
278-
if (index < 0)
286+
int keyIndex = _keysDown.IndexOf(key);
287+
if (keyIndex < 0)
279288
Console.WriteLine($"[ERROR] Double key up detected? K{keyboard.Index}> {key} up.");
280289
else
281-
_keysDown.RemoveAt(index);
290+
_keysDown.RemoveAt(keyIndex);
282291
}
292+
293+
int scancodeIndex = _scancodesDown.IndexOf(scancode);
294+
if (scancodeIndex < 0)
295+
Console.WriteLine($"[ERROR] Double scancode up detected? K{keyboard.Index}> {scancode} up.");
296+
else
297+
_scancodesDown.RemoveAt(scancodeIndex);
283298
}
284299

285300
private static void KeyboardOnKeyDown(IKeyboard keyboard, Key key, int scancode)
@@ -293,6 +308,11 @@ private static void KeyboardOnKeyDown(IKeyboard keyboard, Key key, int scancode)
293308
else
294309
_keysDown.Add(key);
295310
}
311+
312+
if (_scancodesDown.Contains(scancode))
313+
Console.WriteLine($"[ERROR] Double scancode down detected? K{keyboard.Index}> {scancode} down.");
314+
else
315+
_scancodesDown.Add(scancode);
296316
}
297317
}
298318
}

0 commit comments

Comments
 (0)