Version: v0.0.0-...-e5c040b Latest Latest

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

Go to latest
Published: Nov 30, 2021 License: MIT, Unlicense Imports: 5 Imported by: 107



Package key implements key and text events and operations.

The InputOp operations is used for declaring key input handlers. Use an implementation of the Queue interface from package ui to receive events.



View Source
const (
	// Names for special keys.
	NameLeftArrow      = "←"
	NameRightArrow     = "→"
	NameUpArrow        = "↑"
	NameDownArrow      = "↓"
	NameReturn         = "⏎"
	NameEnter          = "⌤"
	NameEscape         = "⎋"
	NameHome           = "⇱"
	NameEnd            = "⇲"
	NameDeleteBackward = "⌫"
	NameDeleteForward  = "⌦"
	NamePageUp         = "⇞"
	NamePageDown       = "⇟"
	NameTab            = "⇥"
	NameSpace          = "Space"
View Source
const ModShortcut = ModCtrl

ModShortcut is the platform's shortcut modifier, usually the Ctrl key. On Apple platforms it is the Cmd key.


This section is empty.


This section is empty.


type EditEvent

type EditEvent struct {
	Text string

An EditEvent is generated when text is input.

func (EditEvent) ImplementsEvent

func (EditEvent) ImplementsEvent()

type Event

type Event struct {
	// Name of the key. For letters, the upper case form is used, via
	// unicode.ToUpper. The shift modifier is taken into account, all other
	// modifiers are ignored. For example, the "shift-1" and "ctrl-shift-1"
	// combinations both give the Name "!" with the US keyboard layout.
	Name string
	// Modifiers is the set of active modifiers when the key was pressed.
	Modifiers Modifiers
	// State is the state of the key when the event was fired.
	State State

An Event is generated when a key is pressed. For text input use EditEvent.

func (Event) ImplementsEvent

func (Event) ImplementsEvent()

func (Event) String

func (e Event) String() string

type FocusEvent

type FocusEvent struct {
	Focus bool

A FocusEvent is generated when a handler gains or loses focus.

func (FocusEvent) ImplementsEvent

func (FocusEvent) ImplementsEvent()

type FocusOp

type FocusOp struct {
	// Tag is the new focus. The focus is cleared if Tag is nil, or if Tag
	// has no InputOp in the same frame.
	Tag event.Tag

FocusOp sets or clears the keyboard focus. It replaces any previous FocusOp in the same frame.

func (FocusOp) Add

func (h FocusOp) Add(o *op.Ops)

type InputHint

type InputHint uint8

InputHint changes the on-screen-keyboard type. That hints the type of data that might be entered by the user.

const (
	// HintAny hints that any input is expected.
	HintAny InputHint = iota
	// HintText hints that text input is expected. It may activate auto-correction and suggestions.
	// HintNumeric hints that numeric input is expected. It may activate shortcuts for 0-9, "." and ",".
	// HintEmail hints that email input is expected. It may activate shortcuts for common email characters, such as "@" and ".com".
	// HintURL hints that URL input is expected. It may activate shortcuts for common URL fragments such as "/" and ".com".
	// HintTelephone hints that telephone number input is expected. It may activate shortcuts for 0-9, "#" and "*".

type InputOp

type InputOp struct {
	Tag  event.Tag
	Hint InputHint

InputOp declares a handler ready for key events. Key events are in general only delivered to the focused key handler.

func (InputOp) Add

func (h InputOp) Add(o *op.Ops)

type Modifiers

type Modifiers uint32


const (
	// ModCtrl is the ctrl modifier key.
	ModCtrl Modifiers = 1 << iota
	// ModCommand is the command modifier key
	// found on Apple keyboards.
	// ModShift is the shift modifier key.
	// ModAlt is the alt modifier key, or the option
	// key on Apple keyboards.
	// ModSuper is the "logo" modifier key, often
	// represented by a Windows logo.

func (Modifiers) Contain

func (m Modifiers) Contain(m2 Modifiers) bool

Contain reports whether m contains all modifiers in m2.

func (Modifiers) String

func (m Modifiers) String() string

type SoftKeyboardOp

type SoftKeyboardOp struct {
	Show bool

SoftKeyboardOp shows or hide the on-screen keyboard, if available. It replaces any previous SoftKeyboardOp.

func (SoftKeyboardOp) Add

func (h SoftKeyboardOp) Add(o *op.Ops)

type State

type State uint8

State is the state of a key during an event.

const (
	// Press is the state of a pressed key.
	Press State = iota
	// Release is the state of a key that has been released.
	// Note: release events are only implemented on the following platforms:
	// macOS, Linux, Windows, WebAssembly.

func (State) String

func (s State) String() string

Source Files

Jump to

Keyboard shortcuts

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