Martin Häger
Full-stack software developer with DevOps experience. Blogging about programming, video games, music, electronics engineering, and all things DIY.

Nintendo Switch Virtual Keyboard
Published on January 23rd 2019

libnx is now capable of calling up system applets, including the virtual keyboard and captive portal browser. With these two components, it should be straightforward to implement a makeshift web browser. Here's how you use the keyboard:

#include <stdio.h>
#include <switch.h>

int main(int argc, char* argv[]) {
	SwkbdConfig kbd;
	Result rc;

	consoleInit(NULL);
	rc = swkbdCreate(&kbd, 0);

	if (R_SUCCEEDED(rc)) {
		swkbdConfigMakePresetDefault(&kbd);

		char input[16] = {0};
		rc = swkbdShow(&kbd, input, sizeof(input));

		if (R_SUCCEEDED(rc)) {
			printf("Got input: %s\n", input);
		} else {
			fprintf(stderr, "swkbdShow() error: %u\n", rc);
		}

		swkbdClose(&kbd);
	} else {
		fprintf(stderr, "swkbdCreate() error: %u\n", rc);
	}

	printf("Press + to exit.\n");

	while (appletMainLoop()) {
		hidScanInput();
		u64 keyDown = hidKeysDown(CONTROLLER_P1_AUTO);

		if (keyDown & KEY_PLUS) {
			break;
		}

		consoleUpdate(NULL);
	}

	consoleExit(NULL);
}

Screenshots

Text input
Text input

Printing it out
Printing it out

Enjoyed this post? Got feedback? Consider following @kvadevack for the latest updates.

This post, excluding sample code, is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. See the example directory for code licensing.

© Martin Häger, 2018 - 2021.

v1.5.12 (changelog). Built with GraphQL, React and Semantic UI.