Index | Files

package key

import ""

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.


Package Files

key.go mod.go


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

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

type EditEvent Uses

type EditEvent struct {
    Text string

An EditEvent is generated when text is input.

func (EditEvent) ImplementsEvent Uses

func (EditEvent) ImplementsEvent()

type Event Uses

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 Uses

func (Event) ImplementsEvent()

func (Event) String Uses

func (e Event) String() string

type FocusEvent Uses

type FocusEvent struct {
    Focus bool

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

func (FocusEvent) ImplementsEvent Uses

func (FocusEvent) ImplementsEvent()

type HideInputOp Uses

type HideInputOp struct{}

HideInputOp request that any on screen text input be hidden.

func (HideInputOp) Add Uses

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

type InputOp Uses

type InputOp struct {
    Tag   event.Tag
    Focus bool

InputOp declares a handler ready for key events. Key events are in general only delivered to the focused key handler. Set the Focus flag to request the focus.

func (InputOp) Add Uses

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

type Modifiers Uses

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 Uses

func (m Modifiers) Contain(m2 Modifiers) bool

Contain reports whether m contains all modifiers in m2.

func (Modifiers) String Uses

func (m Modifiers) String() string

type State Uses

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 Uses

func (s State) String() string

Package key imports 5 packages (graph) and is imported by 40 packages. Updated 2020-11-27. Refresh now. Tools for package owners.