Skip to content

Docs menu // site/keys

[ SDK ] /docs/sdk/keys

site/keys

Keyboard shortcuts, in the style of rex.bind.

import
import keys from "site/keys"

A key is modifiers and a key joined by "+" ("shift+g", "?", "g>w"). A sequence is keys joined by ">" ("g>w"). A key in a mode is written "mode/key" ("nav/j") and only works while that mode is active; Escape leaves a mode. Bindings name an action: a script action or a built-in one. Keys never fire while the visitor is typing in a field.

Functions#

SignatureDescription
fn bind(key: string, action: string) -> voidBinds a key, a sequence or a mode key to an action name. A binding to a name that does not exist toasts a warning when pressed.
fn unbind(key: string) -> voidRemoves a binding. The key is written the same way it was bound.
fn mode(name: string, exclusive: bool) -> voiddeclare a mode's options
fn enter(mode: string) -> voidMakes a mode the active one. Its bindings now apply; Escape leaves it.
fn exit() -> voidLeaves the active mode.

Examples#

Bindings, sequences and modes
import site from "site"
import keys from "site/keys"

site.action(site.Action {
    name: "go_work",
    title: "Go to work",
    description: "",
    category: "Docs",
    keywords: [],
    run: () => site.goto("work"),
})

keys.bind("shift+w", "go_work")
keys.bind("g>w", "go_work")

keys.mode("nav", true)
keys.bind("nav/w", "go_work")
keys.bind("nav/q", "go_work")
keys.unbind("nav/q")

Limits#

  • At most 128 bindings. A binding string is at most 64 characters, with at most 4 keys in a sequence and 1 second allowed between them.
  • Modifiers are ctrl, alt, shift and meta (also control, option, opt, cmd, command and super). Named keys include escape, enter, space, tab, backspace, up, down, left and right.
  • Reserved keys cannot be bound, and a bind to one is ignored with an error line in the console output: every ctrl, alt and meta chord, enter, space, tab, escape, f1 to f12 and the backtick. Plain keys, shift+keys and sequences of them are fine. Keys are ignored while the visitor is typing in a field, and while the console or palette is open.
  • A mode name is a lowercase letter followed by up to 15 letters, digits or underscores. An exclusive mode ignores the global bindings and swallows keys nobody bound.

Declaration file#

This page is generated from the file below, served as /eitri/sdk/site/keys.eith. Types and signatures are exactly what the compiler checks scripts against. Back to all modules.

site/keys.eith
// site/keys: keyboard shortcuts, in the style of rex.bind.
//
// A key is modifiers and a key joined by "+" ("shift+g", "?", "g>w").
// A sequence is keys joined by ">" ("g>w"). A key in a mode is written
// "mode/key" ("nav/j") and only works while that mode is active; Escape
// leaves a mode. Bindings name an action: a script action or a built-in one.
// Keys never fire while the visitor is typing in a field.

pub fn bind(key: string, action: string) -> void
pub fn unbind(key: string) -> void
pub fn mode(name: string, exclusive: bool) -> void   // declare a mode's options
pub fn enter(mode: string) -> void
pub fn exit() -> void