// Include the most common headers from the C standard library #include #include #include #include // Include the main libnx system header, for Switch development #include // See also libnx swkbd.h. // This example shows how to use the software keyboard (swkbd) LibraryApplet. // TextCheck callback, this can be removed when not using TextCheck. SwkbdTextCheckResult validate_text(char* tmp_string, size_t tmp_string_size) { if (strcmp(tmp_string, "bad")==0) { strncpy(tmp_string, "Bad string.", tmp_string_size); return SwkbdTextCheckResult_Bad; } return SwkbdTextCheckResult_OK; } // Main program entrypoint int main(int argc, char* argv[]) { Result rc=0; // This example uses a text console, as a simple way to output text to the screen. // If you want to write a software-rendered graphics application, // take a look at the graphics/simplegfx example, which uses the libnx gfx API instead. // If on the other hand you want to write an OpenGL based application, // take a look at the graphics/opengl set of examples, which uses EGL instead. consoleInit(NULL); printf("swkbd example\n"); consoleUpdate(NULL); SwkbdConfig kbd; char tmpoutstr[16] = {0}; rc = swkbdCreate(&kbd, 0); printf("swkbdCreate(): 0x%x\n", rc); if (R_SUCCEEDED(rc)) { // Select a Preset to use, if any. swkbdConfigMakePresetDefault(&kbd); //swkbdConfigMakePresetPassword(&kbd); //swkbdConfigMakePresetUserName(&kbd); //swkbdConfigMakePresetDownloadCode(&kbd); // Optional, set any text if you want (see swkbd.h). //swkbdConfigSetOkButtonText(&kbd, "Submit"); //swkbdConfigSetLeftOptionalSymbolKey(&kbd, "a"); //swkbdConfigSetRightOptionalSymbolKey(&kbd, "b"); //swkbdConfigSetHeaderText(&kbd, "Header"); //swkbdConfigSetSubText(&kbd, "Sub"); //swkbdConfigSetGuideText(&kbd, "Guide"); swkbdConfigSetTextCheckCallback(&kbd, validate_text);//Optional, enable to use TextCheck. // Set the initial string if you want. //swkbdConfigSetInitialText(&kbd, "Initial"); // You can set arg fields directly if you want. printf("Running swkbdShow...\n"); rc = swkbdShow(&kbd, tmpoutstr, sizeof(tmpoutstr)); printf("swkbdShow(): 0x%x\n", rc); if (R_SUCCEEDED(rc)) { printf("out str: %s\n", tmpoutstr); } swkbdClose(&kbd); } printf("Press + to exit.\n"); // Main loop while (appletMainLoop())//This loop will automatically exit when applet requests exit. { // Scan all the inputs. This should be done once for each frame hidScanInput(); // hidKeysDown returns information about which buttons have been // just pressed in this frame compared to the previous one u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); if (kDown & KEY_PLUS) break; // break in order to return to hbmenu // Your code goes here // Update the console, sending a new frame to the display consoleUpdate(NULL); } // Deinitialize and clean up resources used by the console (important!) consoleExit(NULL); return 0; }