KEYBOARD(3)

πŸ“¦ version 0_git20260208, in alpine 3.24, arch rolling, nixos 26.05, nixpkgs unstable

okay so bestie, welcome to KEYBOARD(3) from the Library Functions Manual πŸ’– this is the keyboard-control page, and it’s giving multi-threaded character-at-a-time realness. let’s go.

πŸŽ€ NAME πŸŽ€

initkeyboard, ctlkeyboard, closekeyboard β€” keyboard control, and that’s the whole name section, no cap.

✨ SYNOPSIS ✨

#include <u.h>
#include <libc.h>
#include <thread.h>
#include <keyboard.h>

Keyboardctl    *initkeyboard(char *file)

int            ctlkeyboard(Keyboardctl *kc, char *msg)

void           closekeyboard(Keyboard *kc)

πŸ’… DESCRIPTION πŸ’…

okay so the whole vibe: these functions access and control a keyboard interface for character-at-a-time I/O in a multi-threaded environment, usually in combination with mouse(3). They use the message-passing Channel interface in the threads library (see thread(3)); programs that wish a more event-driven, single-threaded approach should use event(3). slay.

initkeyboard opens a connection to the keyboard and returns a Keyboardctl structure β€” say hi:

typedef struct Keyboardct Keyboardctl;
struct Keyboardctl
{
      Channel *c;       /* chan(Rune[20]) */

      char    *file;
      int     consfd;   /* to cons file */
      int     ctlfd;    /* to ctl file */
      int     pid;      /* of slave proc */
};

The argument to initkeyboard is ignored (on Plan 9, it is the name of the keyboard device). iykyk.

Once the Keyboardctl is set up a message containing a Rune will be sent on the Channel Keyboardctl.c to report each character read from the device. literally each character, one at a time, main character energy.

ctlkeyboard is used to set the state of the interface, typically to turn raw mode on and off. It writes the string msg to the control file associated with the device, which is assumed to be the regular device file name with the string ctl appended. that’s the whole assignment, bestie.

closekeyboard closes the file descriptors associated with the keyboard, kills the slave processes, and frees the Keyboardctl structure. cleanup queen behavior ✨.


🌈 SOURCE 🌈

/src/libdraw

πŸ¦‹ SEE ALSO πŸ¦‹

πŸ’€ BUGS πŸ’€

⚠️ Because the interface delivers complete runes, there is no way to report lesser actions such as shift keys or even individual bytes. that’s the tea: no shift-key side quests, no single-byte crumbs. periodt.

okay bye bestie β€” this was KEYBOARD(3) from the Library Functions Manual, source /src/libdraw, and the footer is literally just KEYBOARD(3) with no extra version/date drama πŸ’…βœ¨