Skip to content

Class Keyboard ​

A seat's keyboard, from seat:keyboard(), event.keyboard or the new_keyboard event.

All keyboard devices on a seat share one keyboard.

  • Plugging in another device gives the seat a new keyboard with the default layout.
  • new_keyboard doesn't fire again after a reload.

Set up new keyboards and the ones already there:

lua
local function set_up_keyboard(new_keyboard)
	new_keyboard.layout = "us"
	new_keyboard.repeat_rate = 30
	new_keyboard.repeat_delay = 300
end

for _, each_seat in ipairs(wm.input.seats:all()) do
	local seat_keyboard = each_seat:keyboard()
	if seat_keyboard then set_up_keyboard(seat_keyboard) end
end
wm.input:on("new_keyboard", set_up_keyboard)

The layout and repeat settings stay through a reload.

Properties ​

keyboard.layout: stringlayout ​

The keyboard layout. Set it to an xkb layout name such as "us" or "de", the names setxkbmap takes.

  • A comma list such as "us,de" loads several layouts.
  • Reads back as the active layout's display name, such as "English (US)", not the name it was set to.

Errors for a name xkb can't load. The layout stays as it was.

keyboard.repeat_rate: integerrepeat_rate ​

How many times a second a held key repeats.

  • Default: 25. 0 turns repeat off.
  • One setting for every keyboard, new ones included.

Errors for a negative value.

keyboard.repeat_delay: integerrepeat_delay ​

How many milliseconds a key is held before it starts repeating.

  • Default: 200.
  • One setting for every keyboard, like the rate.

Errors for a negative value.

Methods ​

keyboard:seat() -> Seat?seat ​

The seat this keyboard is on.

  • nil once the seat has a newer keyboard or none.

keyboard:key(evdev_code: integer, state: "pressed" | "released") -> nilkey ​

Presses or releases a key as if it came from the device. evdev_code is the value from Linux input-event-codes.h: 30 is A, 42 is left Shift, 125 is left Super.

  • The key handlers run before it returns. The focused app then gets the key unless a handler prevented it.
  • state may also be "Pressed" or "Released".
  • The event's time is 0.
  • Release every key you press, or the app thinks it is still held.

Errors for any other state.

lua
local KEY_LEFTCTRL, KEY_C = 29, 46
keyboard:key(KEY_LEFTCTRL, "pressed")
keyboard:key(KEY_C, "pressed")
keyboard:key(KEY_C, "released")
keyboard:key(KEY_LEFTCTRL, "released")