Hello,
I have a problem with the touch-detecting part of my code. I am making a keyboard on the bottom screen that you tap to type in commands. I cannot use other keyboards because I need special keys. So far, the keyboard is showing, but there is no tapping recognized. I have implemented a print function to print the status of the PX/PY variables, but they are always 0. Here is the code:
Why does it not work?
I have a problem with the touch-detecting part of my code. I am making a keyboard on the bottom screen that you tap to type in commands. I cannot use other keyboards because I need special keys. So far, the keyboard is showing, but there is no tapping recognized. I have implemented a print function to print the status of the PX/PY variables, but they are always 0. Here is the code:
Code:
std::map<int, std::map<int, char> > char_low = {
{2, {
{2, '`'},
{4, '1'},
{6, '2'},
{8, '3'},
{10, '4'},
{12, '5'},
{14, '6'},
{16, '7'},
{18, '8'},
{20, '9'},
{22, '0'},
{24, '-'},
{26, '='},
}},
{4, {
{7, 'q'},
{9, 'w'},
{11, 'e'},
{13, 'r'},
{15, 't'},
{17, 'y'},
{19, 'u'},
{21, 'i'},
{23, 'o'},
{25, 'p'},
{27, '['},
{29, ']'},
{31, '\\'},
}},
{6, {
{8, 'a'},
{10, 's'},
{12, 'd'},
{13, 'f'},
{15, 'g'},
{17, 'h'},
{19, 'j'},
{21, 'k'},
{23, 'l'},
{25, ';'},
{27, '\''},
}},
{8, {
{8, 'z'},
{10, 'x'},
{12, 'c'},
{14, 'v'},
{16, 'b'},
{18, 'n'},
{20, 'm'},
{22, ','},
{24, '.'},
{26, '/'},
}}
};
std::string keyboardLow = "\
---------------------------------\n\
|`|1|2|3|4|5|6|7|8|9|0|-|=| del |\n\
|-------------------------------|\n\
| |q|w|e|r|t|y|u|i|o|p|[|]|\\|\n\
|-------------------------------|\n\
|ocaps|a|s|d|f|g|h|j|k|l|;|\'|ret|\n\
|-------------------------------|\n\
|shift|z|x|c|v|b|n|m|,|.|/|shift|\n\
|-------------------------------|\n\
|fn|cn|alt|ds| |ds|alt|cn|\n\
---------------------------------";
char getChar(int caps_stat) {
touchPosition touch;
s16 keyX, keyY;
hidWaitForEvent(HIDEVENT_PAD0, false);
hidTouchRead(&touch);
keyX = touch.px / 6;
keyY = touch.py / 6;
printf("PX: %d\tPY: %d\tkeyX: %d\tkeyY: %d\n", touch.px, touch.py, keyX, keyY);
std::map<int, std::map<int, char> > char_locs;
if (caps_stat == 0) char_locs = char_low;
else char_locs = char_up;
char typedKey;
try {char typedKey = char_locs[keyY][keyX];}
catch (const std::out_of_range& oor) {
if (keyY == 2 && intBetween(keyX, 28, 32)) char typedKey = '\x10';
else if (keyY == 6) {
if (intBetween(keyX, 2, 6)) caps = 1;
else if (intBetween(keyX, 30, 32)) char typedKey = '\x11';
}
else if (keyY == 8) {
if (intBetween(keyX, 2, 6) || intBetween(keyX, 28, 32)) caps = 2;
}
else if (keyY == 10) {
if (intBetween(keyX, 2, 3)) char typedKey = '\x12';
else if (intBetween(keyX, 5, 6)) char typedKey = '\x13';
else if (intBetween(keyX, 8, 10)) char typedKey = '\x14';
else if (intBetween(keyX, 12, 13)) char typedKey = '\x15';
else if (intBetween(keyX, 15, 22)) char typedKey = ' ';
else if (intBetween(keyX, 24, 25)) char typedKey = '\x15';
else if (intBetween(keyX, 27, 29)) char typedKey = '\x14';
else if (intBetween(keyX, 31, 32)) char typedKey = '\x13';
}
else char typedKey;
}
if (caps_stat == 2) {
caps = 0;
clk();
printf(keyboardLow.c_str());
consoleSelect(&console);
}
if (caps == 1 && caps_stat == 0) {
clk();
printf(keyboardUp.c_str());
consoleSelect(&console);
}
if (caps == 2) {
clk();
printf(keyboardUp.c_str());
consoleSelect(&console);
}
return typedKey;
}