Documentation
¶
Overview ¶
Package key defines the key event types and modifier constants used by the Kite terminal UI engine.
Key Struct ¶
Key carries the pressed key's rune Code, an optional PC-101 BaseCode (for non-ASCII keyboard layouts), the optional printable Text, a Mod bitmask for modifiers (Ctrl, Alt, Shift, Meta, Hyper, Super, CapsLock, NumLock, ScrollLock), and an IsRepeat flag for auto-repeat events generated by the OS.
Key Matching ¶
MatchString(s ...string) reports whether k matches any of the given string expressions. Expressions use "+" to separate modifiers and key names, e.g. "ctrl+c", "alt+enter", "shift+up". The mapping between string names and rune constants is defined in the stringKeyType map.
Constants ¶
Key codes are split into directional keys (Up, Down, Left, Right), function keys (F1–F63), keypad keys, media keys, modifier keys, and ASCII control codes (C0). The Kitty keyboard extension constants are also included when available.
Example:
if k.MatchString("ctrl+c") {
// handle copy
}
Index ¶
Constants ¶
const ( KeyUp rune = KeyExtended + iota + 1 KeyDown KeyRight KeyLeft KeyBegin KeyFind KeyInsert KeyDelete KeySelect KeyPgUp KeyPgDown KeyHome KeyEnd KeyKpEnter KeyKpEqual KeyKpMultiply KeyKpPlus KeyKpComma KeyKpMinus KeyKpDecimal KeyKpDivide KeyKp0 KeyKp1 KeyKp2 KeyKp3 KeyKp4 KeyKp5 KeyKp6 KeyKp7 KeyKp8 KeyKp9 KeyKpSep KeyKpUp KeyKpDown KeyKpLeft KeyKpRight KeyKpPgUp KeyKpPgDown KeyKpHome KeyKpEnd KeyKpInsert KeyKpDelete KeyKpBegin KeyF1 KeyF2 KeyF3 KeyF4 KeyF5 KeyF6 KeyF7 KeyF8 KeyF9 KeyF10 KeyF11 KeyF12 KeyF13 KeyF14 KeyF15 KeyF16 KeyF17 KeyF18 KeyF19 KeyF20 KeyF21 KeyF22 KeyF23 KeyF24 KeyF25 KeyF26 KeyF27 KeyF28 KeyF29 KeyF30 KeyF31 KeyF32 KeyF33 KeyF34 KeyF35 KeyF36 KeyF37 KeyF38 KeyF39 KeyF40 KeyF41 KeyF42 KeyF43 KeyF44 KeyF45 KeyF46 KeyF47 KeyF48 KeyF49 KeyF50 KeyF51 KeyF52 KeyF53 KeyF54 KeyF55 KeyF56 KeyF57 KeyF58 KeyF59 KeyF60 KeyF61 KeyF62 KeyF63 KeyCapsLock KeyScrollLock KeyNumLock KeyPrintScreen KeyPause KeyMenu KeyMediaPlay KeyMediaPause KeyMediaPlayPause KeyMediaReverse KeyMediaStop KeyMediaFastForward KeyMediaRewind KeyMediaNext KeyMediaPrev KeyMediaRecord KeyLowerVol KeyRaiseVol KeyMute KeyLeftShift KeyLeftAlt KeyLeftCtrl KeyLeftSuper KeyLeftHyper KeyLeftMeta KeyRightShift KeyRightAlt KeyRightCtrl KeyRightSuper KeyRightHyper KeyRightMeta KeyIsoLevel3Shift KeyIsoLevel5Shift KeyBackspace = rune(0x7f) KeyTab = rune(0x09) KeyEnter = rune(0x0d) KeyReturn = KeyEnter KeyEscape = rune(0x1b) KeyEsc = KeyEscape KeySpace = rune(0x20) // ASCII Control Codes (C0) CtrlC = rune(0x03) // ETX (End of Text) CtrlV = rune(0x16) // SYN (Synchronous Idle) CtrlX = rune(0x18) // CAN (Cancel) )
Special key symbols.
const ( // KeyExtended is a special key code used to signify that a key event // contains multiple runes. KeyExtended = unicode.MaxRune + 1 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Key ¶
type Key struct {
// Text contains the actual characters received. This usually the same as
// [Key.Code]. When [Key.Text] is non-empty, it indicates that the key
// pressed represents printable character(s).
Text string
// Code represents the key pressed.
// E.g., [KeyTab], [KeyEnter], [KeyArrowUp], etc.
Code rune
// BaseCode is the unmodified key code on a standard PC-101 physical layout
// (reported via the Kitty keyboard protocol). It allows shortcuts like
// Ctrl+C to match on non-ASCII layouts (e.g. Cyrillic) while preserving
// remapped ASCII layouts (Dvorak, Colemak).
BaseCode rune
// IsRepeat indicates whether this key event is a repeat (i.e., the key is being held
// down and the event is generated by the system's key repeat mechanism). When true, this
// event should be treated as a repeat of the previous key event, and may be ignored by
// some applications that only want to respond to the initial key press.
IsRepeat bool
// Mod is a bitmask of modifier keys (e.g., Ctrl, Alt, Shift) that were held down when the key event occurred. The specific modifier keys and their corresponding bit values are defined by the application or library handling the key events.
Mod Mod
}