Homebrew Homebrew Program with Touch Detection Not Detecting Touch

JackMacWindows

Well-Known Member
OP
Newcomer
Joined
Jan 16, 2016
Messages
53
Trophies
0
XP
258
Country
United States
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:
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;
}
Why does it not work?
 

daxtsu

Well-Known Member
Member
Joined
Jun 9, 2007
Messages
5,627
Trophies
2
XP
5,194
Country
Antarctica
If hidScanInput doesn't do it either, make sure it's not a hardware problem by testing it in an actual 3DS commercial game.
 

JackMacWindows

Well-Known Member
OP
Newcomer
Joined
Jan 16, 2016
Messages
53
Trophies
0
XP
258
Country
United States
You must call an hidScanInput() to update hid shared-mem.
I noticed that and fixed it, but now I have another problem.
I put the TouchRead, keyX, and keyY in a while (touch.px == 0) loop, but it never comes out and actually finishes.

--------------------- MERGED ---------------------------

Ok, so this:
Code:
while (touch.px == 0 && touch.py == 0) {
    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);
    }
is not picking up the touch coordinates. When I touch, it still prints "PX: 0 PY: 0 keyX: 0 keyY: 0"
 

mashers

Stubborn ape
Member
Joined
Jun 10, 2015
Messages
3,837
Trophies
0
Age
40
Location
Kongo Jungle
XP
5,074
Country
I noticed that and fixed it, but now I have another problem.
I put the TouchRead, keyX, and keyY in a while (touch.px == 0) loop, but it never comes out and actually finishes.

--------------------- MERGED ---------------------------

Ok, so this:
Code:
while (touch.px == 0 && touch.py == 0) {
    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);
    }
is not picking up the touch coordinates. When I touch, it still prints "PX: 0 PY: 0 keyX: 0 keyY: 0"
That's because the line which prints the coordinates is only within the while loop, so the coordinates are only ever printed when the coordinates are 0x0.

Edit - while loop, not if statement.
 
Last edited by mashers,

daxtsu

Well-Known Member
Member
Joined
Jun 9, 2007
Messages
5,627
Trophies
2
XP
5,194
Country
Antarctica
I noticed that and fixed it, but now I have another problem.
I put the TouchRead, keyX, and keyY in a while (touch.px == 0) loop, but it never comes out and actually finishes.

--------------------- MERGED ---------------------------

Ok, so this:
Code:
while (touch.px == 0 && touch.py == 0) {
    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);
    }
is not picking up the touch coordinates. When I touch, it still prints "PX: 0 PY: 0 keyX: 0 keyY: 0"

Because you have to call hidScanInput first before reading the touch data. It doesn't update if you're not scanning for new input.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    Xdqwerty @ Xdqwerty: roms wont boot with wood r4menu