key

package
v0.11.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package key represents keys on the keyboard that the user might type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StringToKeys

func StringToKeys(s string, o ...keyOption) iter.Seq[Key]

StringToKeys returns a sequence of Key given an input string s containing text. If the string contains upper-case letters, the sequence will include a keydown event for the shift key, the keydown/keyup events for the actual key, and finally the keyup event for the shoft key.

func WithKeydownDelay added in v0.11.3

func WithKeydownDelay(d time.Duration) keyOption

func WithKeyupDelay added in v0.11.3

func WithKeyupDelay(d time.Duration) keyOption

Types

type Key

type Key struct {
	Key    string
	Letter string
	// KeydownDelay defines the simulated delay after the keydown event before
	// the next keyevent is dispatched.
	KeydownDelay time.Duration
	// KeyupDelay defines the simulated delay after the keyup event before the
	// next keyevent is dispatched.
	KeyupDelay time.Duration
	Down, Up   bool
}

Key represents a single keyboard input. WARNING: This is experimental.

The fields Up and Down indicate if up/down events should be dispatched, which is used for simple modifier keys, e.g., the sequence Shift+A would generate the following sequence:

  • Key: Shift, Down: true, Up: false
  • Key: A, Down: true, Up: true
  • Key: Shift, Down: false, Up: true

Modifier states are not properly represented, the individual keyboard events do not contain modifier information, i.e., in the previous example, the event for the "A" key doesn't include the shiftKey yet.

When simulating a string of keyboard events, KeydownDelay and KeyupDelay describes simulated delay after the keydown/keyup event before the next keyboard event in the sequence.

func RuneToKey

func RuneToKey(r rune) Key

RuneToKey returns a Key representing the keyboard key with the letter specified.

func (Key) EventInit added in v0.9.1

func (k Key) EventInit() uievents.KeyboardEventInit

EventInit creates a KeyboardEventInit representing the key stroke.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL