Keys: which ones are held, not only which were pressed

Apps heard a key once, when it went down. A Game that moves something
for as long as a key is held (issue #101) asks the key mapper instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0162FokPdvY2KsS4NBfwyWPk
This commit is contained in:
2026-10-13 22:59:05 +02:00
co-authored by Claude Opus 5.5
parent 8aa2848c5f
commit 5c660d866d
3 changed files with 77 additions and 0 deletions
+18
View File
@@ -54,6 +54,24 @@ KeyEvent keyEvent(Key key, const RawKeys& keys) {
} // namespace
bool KeyMapper::heldChar(char c) const {
return std::find(previous_.chars.begin(), previous_.chars.end(), c) != previous_.chars.end();
}
bool KeyMapper::held(Key key) const {
bool arrows = previous_.fn || !textEntry_;
switch (key) {
case Key::Up: return arrows && heldChar(';');
case Key::Down: return arrows && heldChar('.');
case Key::Left: return arrows && heldChar(',');
case Key::Right: return arrows && heldChar('/');
case Key::Select: return previous_.enter;
case Key::Delete: return previous_.del;
case Key::Tab: return previous_.tab;
default: return false;
}
}
std::vector<KeyEvent> KeyMapper::update(const RawKeys& keys) {
std::vector<KeyEvent> out;