Nintendo 3DS >> C/C++

Software Keyboard


參考資訊:
1. libctru doc
2. 3ds-examples

說明:

API
void swkbdInit(SwkbdState *swkbd, SwkbdType type, int numButtons, int maxTextLength)
void swkbdSetInitialText(SwkbdState *swkbd, const char *text)
void swkbdSetHintText(SwkbdState *swkbd, const char *text)
void swkbdSetButton(SwkbdState *swkbd, SwkbdButton button, const char *text, bool submit)
void swkbdSetFeatures(SwkbdState *swkbd, u32 features)
SwkbdButton swkbdInputText(SwkbdState *swkbd, char *buf, size_t bufsize)

main.c

#include <3ds.h>
#include <stdio.h>
#include <string.h>

int main(void)
{
    char mybuf[255] = {0};
    SwkbdState swkbd = {0};
    SwkbdButton button = SWKBD_BUTTON_NONE;
        
    gfxInitDefault();
    consoleInit(GFX_TOP, NULL);

    swkbdInit(&swkbd, SWKBD_TYPE_NORMAL, 3, -1);
    swkbdSetInitialText(&swkbd, mybuf);
    swkbdSetHintText(&swkbd, "Please input your text");
    swkbdSetButton(&swkbd, SWKBD_BUTTON_LEFT, "No", false);
    swkbdSetButton(&swkbd, SWKBD_BUTTON_MIDDLE, " ", true);
    swkbdSetButton(&swkbd, SWKBD_BUTTON_RIGHT, "Yes", true);
    swkbdSetFeatures(&swkbd, SWKBD_PREDICTIVE_INPUT);

    button = swkbdInputText(&swkbd, mybuf, sizeof(mybuf));
    if (button != SWKBD_BUTTON_NONE) {
        printf("Text: %s\n", mybuf);
    } 

    gfxFlushBuffers();
    gfxSwapBuffers();
    gspWaitForVBlank();
    svcSleepThread(3000000000LL);
    gfxExit();
    return 0;
}

完成


返回上一頁