From 24d912eab0c509537d6faf8f77696ff6c0b81a39 Mon Sep 17 00:00:00 2001 From: Dimitri Sophinos Date: Thu, 19 Oct 2023 12:34:06 -0400 Subject: [PATCH] detect what key is pressed + some modifiers --- platform/3ds/source/Keyboard.cpp | 48 ++++++++++++++++++++++++++++++-- platform/3ds/source/Keyboard.h | 15 ++++++---- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/platform/3ds/source/Keyboard.cpp b/platform/3ds/source/Keyboard.cpp index d322ffe0..a0222175 100644 --- a/platform/3ds/source/Keyboard.cpp +++ b/platform/3ds/source/Keyboard.cpp @@ -4,6 +4,7 @@ #include "../../source/logger.h" #include "../../source/host.h" +#include "../../source/emojiconversion.h" Keyboard::Keyboard(){ @@ -91,6 +92,10 @@ void Keyboard::GetKey(bool& currKBDown, std::string& currKBKey, touchPosition& t repeatingKey = false; return; } + + keyX = std::min(std::max((touch.px - KEY_XOFFSET) / KEY_WIDTH,0),KEY_COLUMNS - 1); + keyY = std::min(std::max((touch.py - KEY_YOFFSET) / KEY_HEIGHT,0),KEY_ROWS - 1);; + if(touchDown){ repeatTimer += tickSpeed; if(!repeatingKey){ @@ -113,8 +118,47 @@ void Keyboard::GetKey(bool& currKBDown, std::string& currKBKey, touchPosition& t } touchDown = true; - currKBDown = true; - currKBKey = "A"; + + //Logger_Write("%d %d\n", keyX,keyY); + keyStr = layout[keyY][keyX][0]; + keyStrShift = layout[keyY][keyX][1]; + + if(keyStr == "!S"){ //shift key + shift = !shift; + } + else if(keyStr == "!C"){ //ctrl key + ctrl = !ctrl; + } + else if(keyStr == "!A"){ //alt key + alt = !alt; + } + else if(keyStr == "!E"){ //symbol key + symbol = !symbol; + } + else if(keyStr == ".."){ //empty key + shift = false; + ctrl = false; + alt = false; + symbol = false; + } + else{ //other keys + if(symbol){ + currKBKey = charset::upper_to_emoji(keyStrShift); + symbol = false; + } + else if(shift){ + currKBKey = keyStrShift; + shift = false; + } + else{ + currKBKey = keyStr; + } + ctrl = false; //pico 8 cannot actually access modifier keys, might be worth adding as an optional feature? + alt = false; + currKBDown = true; + } + + } diff --git a/platform/3ds/source/Keyboard.h b/platform/3ds/source/Keyboard.h index 7ca9e584..acee888e 100644 --- a/platform/3ds/source/Keyboard.h +++ b/platform/3ds/source/Keyboard.h @@ -5,9 +5,9 @@ #include "../../source/host.h" -#define KEY_WIDTH 30 +#define KEY_WIDTH 26 #define KEY_HEIGHT 36 -#define KEY_XOFFSET 0 +#define KEY_XOFFSET 4 #define KEY_YOFFSET 24 #define KEY_ROWS 6 @@ -18,9 +18,9 @@ const std::string layout[KEY_ROWS][KEY_COLUMNS][2] = { {{"1", "!" },{"2", "@" },{"3", "#" },{"4", "$" },{"5", "%" },{"6", "^" },{"7", "&" },{"8", "*" },{"9", "(" },{"0", ")" },{"-", "_" },{"=", "=" }}, -{{"Q", "q" },{"W", "w" },{"E", "e" },{"R", "r" },{"T", "t" },{"Y", "y" },{"U", "u" },{"I", "i" },{"O", "o" },{"P", "p" },{"[", "{" },{"]", "}" }}, -{{"A", "a" },{"S", "s" },{"D", "d" },{"F", "f" },{"G", "g" },{"H", "h" },{"J", "j" },{"K", "k" },{"L", "l" },{";", ":" },{"'", "\""},{"\r","\r"}}, -{{"Z", "z" },{"X", "x" },{"C", "c" },{"V", "v" },{"B", "b" },{"N", "n "},{"M", "m" },{",", "<" },{".", ">" },{"/", "?" },{"\\","|" },{"\r","\r"}}, +{{"q", "Q" },{"w", "W" },{"e", "E" },{"r", "R" },{"t", "T" },{"y", "Y" },{"u", "U" },{"i", "I" },{"o", "O" },{"p", "P" },{"[", "{" },{"]", "}" }}, +{{"a", "A" },{"s", "S" },{"d", "D" },{"f", "F" },{"g", "G" },{"h", "H" },{"j", "J" },{"k", "K" },{"l", "L" },{";", ":" },{"'", "\""},{"\r","\r"}}, +{{"z", "Z" },{"x", "X" },{"c", "C" },{"v", "V" },{"b", "B" },{"n", "N "},{"m", "M" },{",", "<" },{".", ">" },{"/", "?" },{"\\","|" },{"\r","\r"}}, {{"!S","!S"},{"!S","!S"},{"!S","!S"},{" ", " " },{" ", " " },{" ", " " },{" ", " " },{" ", " " },{"!C","!C"},{"!C","!C"},{"!A","!A"},{"!A","!A"}}, {{"\t","\t"},{"\t","\t"},{"!E","!E"},{"!E","!E"},{"..",".."},{"..",".."},{"..",".."},{"..",".."},{"`" ,"~" },{"\b","\b"},{"\b","\b"},{"\b","\b"}} }; @@ -43,6 +43,11 @@ class Keyboard { int tickSpeed = 1; + int keyX = 0; + int keyY = 0; + std::string keyStr; + std::string keyStrShift; + StretchOption disableStretch; StretchOption enableStretch = AltScreenStretch;