
# Display and Input

> A framebuffer, a keyboard and a mouse for guest programs.

```js
import { createKernel, domCodeToLinux } from "unkernel";

const vm = await createKernel({
  display: { width: 800, height: 600 }, // the guest gets /dev/fb0
  onDisplay: (mode) => console.log(mode), // a program opened it (its mode) or closed it (null)
});

const frame = vm.frame(); // RGBA, or null while nothing draws
if (frame) ctx.putImageData(new ImageData(frame.data, frame.width, frame.height), 0, 0);

addEventListener("keydown", (e) => {
  const key = domCodeToLinux(e.code);
  if (key && vm.evdev.keyboardOpen) vm.evdev.key(key, true);
});
```

`display` is `true` (640x480), a size, or a function that returns the size each time a program first opens the device, such as the window's size. A program may set its own mode, and `onDisplay` reports every change. `frame()` reads the latest picture and `readFrame()` waits for a fresh one.

## Input

With a display, the guest also gets a keyboard and a mouse (evdev, `/dev/input/event0` and `event1`). `evdev` has `key()`, and `button()`, `move()`, `moveTo()` and `wheel()` for a mouse or tablet. `onInput` tells you when a program opens the keyboard and mouse; until then, send keys to the console.

For guest GL, Vulkan and a virtio-gpu display, see [GL, Vulkan and Video](/sdk/graphics). For sound, see [Sound and Camera](/sdk/sound).
