From f01b447af45fe74cacc216acbd190b33c2b1ca5b Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Sun, 26 Nov 2023 12:12:27 -0800 Subject: [PATCH] [Mammoth] Add keycodes for all non-fn keys. --- lib/mammoth/input/keyboard.cpp | 48 +++++++++++++++++++++++++++++++--- lib/mammoth/input/keyboard.h | 15 +++++++++++ 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/lib/mammoth/input/keyboard.cpp b/lib/mammoth/input/keyboard.cpp index fc768d6..560aee9 100644 --- a/lib/mammoth/input/keyboard.cpp +++ b/lib/mammoth/input/keyboard.cpp @@ -55,6 +55,12 @@ void KeyboardListenerBase::ListenLoop() { check(scancode_or.error()); } uint8_t scancode = scancode_or.value(); + + if (scancode == 0xE0) { + extended_on_ = true; + continue; + } + Keycode k = ScancodeToKeycode(scancode); Action a = ScancodeToAction(scancode); HandleKeycode(k, a); @@ -82,12 +88,12 @@ void KeyboardListenerBase::HandleKeycode(Keycode code, Action action) { const char* num = "1234567890"; c = num[code - k1]; } - } else if (code >= kMinus && code <= kPeriod) { + } else if (code >= kMinus && code <= kBacktick) { if (IsShift()) { - const char* sym = "_+{}|?:\"<>"; + const char* sym = "_+{}|?:\"<>~"; c = sym[code - kMinus]; } else { - const char* sym = "-=[]\\/;',."; + const char* sym = "-=[]\\/;',.`"; c = sym[code - kMinus]; } } else if (code == kEnter) { @@ -117,7 +123,35 @@ void KeyboardListenerBase::HandleKeycode(Keycode code, Action action) { Keycode KeyboardListenerBase::ScancodeToKeycode(uint8_t scancode) { // Cancel out the released bit. scancode &= 0x7F; + if (extended_on_) { + extended_on_ = false; + + switch (scancode) { + case 0x1D: + return kRCtrl; + case 0x38: + return kRAlt; + case 0x48: + return kUp; + case 0x4B: + return kLeft; + case 0x4D: + return kRight; + case 0x50: + return kDown; + case 0x53: + return kDelete; + case 0x5B: + return kSuper; + } + dbgln("Unknown extended scancode {x}", scancode); + + return kUnknownKeycode; + } + switch (scancode) { + case 0x01: + return kEsc; case 0x02: return k1; case 0x03: @@ -142,6 +176,8 @@ Keycode KeyboardListenerBase::ScancodeToKeycode(uint8_t scancode) { return kMinus; case 0x0D: return kEquals; + case 0x0E: + return kBackspace; case 0x0F: return kTab; case 0x10: @@ -170,6 +206,8 @@ Keycode KeyboardListenerBase::ScancodeToKeycode(uint8_t scancode) { return kRBrace; case 0x1C: return kEnter; + case 0x1D: + return kLCtrl; case 0x1E: return kA; case 0x1F: @@ -192,6 +230,8 @@ Keycode KeyboardListenerBase::ScancodeToKeycode(uint8_t scancode) { return kSemicolon; case 0x28: return kQuote; + case 0x29: + return kBacktick; case 0x2A: return kLShift; case 0x2B: @@ -218,6 +258,8 @@ Keycode KeyboardListenerBase::ScancodeToKeycode(uint8_t scancode) { return kFSlash; case 0x36: return kRShift; + case 0x38: + return kLAlt; case 0x39: return kSpace; } diff --git a/lib/mammoth/input/keyboard.h b/lib/mammoth/input/keyboard.h index acf39df..cba2d18 100644 --- a/lib/mammoth/input/keyboard.h +++ b/lib/mammoth/input/keyboard.h @@ -49,6 +49,8 @@ enum Keycode { kSpace = 0x30, kEnter = 0x31, kTab = 0x32, + kBackspace = 0x33, + kDelete = 0x34, kMinus = 0x40, kEquals = 0x41, @@ -60,9 +62,20 @@ enum Keycode { kQuote = 0x47, kComma = 0x48, kPeriod = 0x49, + kBacktick = 0x4A, kLShift = 0x50, kRShift = 0x51, + kLCtrl = 0x52, + kRCtrl = 0x53, + kLAlt = 0x54, + kRAlt = 0x55, + kSuper = 0x56, + kEsc = 0x57, + kUp = 0x58, + kDown = 0x59, + kLeft = 0x5A, + kRight = 0x5B, }; enum Action { @@ -96,6 +109,8 @@ class KeyboardListenerBase { private: PortServer server_; + bool extended_on_ = false; + bool lshift_ = false; bool rshift_ = false;