VKBD(4)
VKBD(4) π
okay bestie, so this is a page from the Kernel Interfaces Manual, and it's all about vkbd β the virtual AT keyboard interface. yes you read that right, a keyboard that isn't even real. we love a fake-it-till-you-make-it icon β¨
β¨ NAME β¨
vkbd β the virtual AT keyboard interface π
β¨ SYNOPSIS β¨
device vkbd
that's it. that's the whole summoning ritual. put this in your kernel config and the vibes arrive π¦
β¨ DESCRIPTION β¨
So like, the vkbd interface is a software loopback mechanism β which is a fancy way of saying it's the virtual AT keyboard equivalent of pty(4). Fr fr, vkbd does for virtual AT keyboards exactly what the pty(4) driver does for terminals. Same energy, different hardware. π
The vkbd driver, just like pty(4), serves up two interfaces: a keyboard interface that mimics the usual facility it's simulating (a virtual AT keyboard for vkbd, or a terminal for pty(4)), and a character-special device βcontrolβ interface. Two-for-one, no cap. π
The virtual AT keyboards get named vkbd0, vkbd1, etc. β one for each control device that has been opened. They're like little keyboard babies. π₯Ί
The vkbd interface lets you open the special control device /dev/vkbdctl. When you open it, vkbd hands back a handle for the lowest unused vkbdctl device β and you can use devname(3) to figure out which one you actually got. Iykyk. π
Each virtual AT keyboard supports the usual keyboard interface ioctl(2)s, so you can use it with kbdcontrol(1) like it's any other keyboard, because why should the fake ones be left out. The control device supports exactly the same ioctl(2)s as the virtual AT keyboard device. Writing AT scan codes to the control device generates an input on the virtual AT keyboard, as if the (non-existent) hardware had just received it. Delulu but make it functional. π
The virtual AT keyboard control device, normally /dev/vkbdctlβ¨Nβ©, is exclusive-open β meaning it absolutely cannot be opened if it's already open, no sharing, no splitting, it's giving possessive girlfriend energy π β and it's restricted to the super-user. A read(2) call will return the virtual AT keyboard status structure (defined in <dev/vkbd/vkbd_var.h>) if one is available; if not, it will either block until one is or return EWOULDBLOCK, depending on whether non-blocking I/O has been enabled. Pick your fighter. π«Ά
A write(2) call passes AT scan codes to be βreceivedβ from the virtual AT keyboard. Each AT scan code must be passed as unsigned int. And here's the gotcha that gets everybody: although AT scan codes must be passed as unsigned ints, the size of the buffer passed to write(2) still should be in bytes, i.e.:
static unsigned int codes[] =
{
/* Make Break */
0x1e, 0x9e
};
int
main(void)
{
int fd, len;
fd = open("/dev/vkbdctl0", O_RDWR);
if (fd < 0)
err(1, "open");
/* Note sizeof(codes) - not 2! */
len = write(fd, codes, sizeof(codes));
if (len < 0)
err(1, "write");
close(fd);
return (0);
}
β οΈ bestie the/* Note sizeof(codes) - not 2! */comment is doing the lord's work. usesizeof(codes). do NOT hardcode a2. that is the trap. π¨
Write will block if there is not enough space in the input queue. Patience is a virtue etc etc. πΈ
The control device also supports select(2) for read and write. Multitasking queen. β
On the last close of the control device, the virtual AT keyboard is removed. And all queued scan codes? Thrown away. Gone. Deleted. Sent to the void. π
β¨ SEE ALSO β¨
go read the whole friend group, they're all connected π¦
β¨ HISTORY β¨
The vkbd module was implemented in FreeBSD 6.0. a classic, an icon, a legend, we stan an OG π
β¨ AUTHORS β¨
Maksim Yevmenkin <m_evmenkin@yahoo.com> β thank you for your service, king π
β¨ CAVEATS β¨
π read this part. actually read it. it matters.
The vkbd interface is a software loopback mechanism, and, thus ddb(4) will not work with it. no debugger for you. sad but true.
Current implementation of the syscons(4) driver can accept input from only one keyboard, even if it is virtual. So it is not possible to have both a wired and a virtual keyboard active at the same time. Pick one. There can only be one main character. π
It is, however, in principal possible to obtain AT scan codes from the different sources and write them into the same virtual keyboard. But heads up: the virtual keyboard state synchronization is the user's responsibility. That's on you bestie, the kernel is not holding your hand for that one. π«Ά
and that's the whole page!! π this manual page came from Debian, dated August 12, 2004 β yes, a vintage. an antique. a collector's item. it was doing virtual keyboards before it was cool. π β¨π
mwah, go write some scan codes responsibly π
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms