Documentation
¶
Overview ¶
Package key implements key and text events and operations.
Index ¶
- Constants
- type Caret
- type Code
- type CompositionEvent
- type EditEvent
- type Event
- type Filter
- type FocusCmd
- type FocusDirection
- type FocusEvent
- type FocusFilter
- type InputHint
- type InputHintOp
- type Modifiers
- type MoveFocusCmd
- type Name
- type Range
- type SelectionCmd
- type SelectionEvent
- type Snippet
- type SnippetCmd
- type SnippetEvent
- type SoftKeyboardCmd
- type State
Constants ¶
const ModShortcut = ModCtrl
ModShortcut is the platform's shortcut modifier, usually the ctrl modifier. On Apple platforms it is the cmd key.
const ModShortcutAlt = ModCtrl
ModShortcutAlt is the platform's alternative shortcut modifier, usually the ctrl modifier. On Apple platforms it is the alt modifier.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Caret ¶
type Caret struct {
// Pos is the intersection point of the caret and its baseline.
Pos f32.Point
// Ascent is the length of the caret above its baseline.
Ascent float32
// Descent is the length of the caret below its baseline.
Descent float32
}
Caret represents the position of a caret.
type Code ¶
type Code string
Code identifies a physical key in the typing area, whatever the keyboard layout types with it. Codes are named as in the web's KeyboardEvent.code, after the key's place on a US QWERTY keyboard: "KeyQ" is the key left of "KeyW" on every layout, typing Q on QWERTY, A on AZERTY and ' on Dvorak. There are codes for the letters ("KeyA"-"KeyZ"), the digits ("Digit0"-"Digit9"), "Backquote", "Minus", "Equal", "BracketLeft", "BracketRight", "Backslash", "Semicolon", "Quote", "Comma", "Period", "Slash", "IntlBackslash" and "Space", and for the number pad's digits ("Numpad0"-"Numpad9"), whatever Num Lock has them type.
Bind by Code for keys chosen for where they sit, such as a game's WASD, and by Name for keys chosen for what they say, such as Ctrl+S. Platforms that don't report physical keys leave Event.Code empty; a Filter with a Code then matches the key whose Name it has on a US layout.
type CompositionEvent ¶
type CompositionEvent Range
CompositionEvent is generated when an input method changes the composing range.
func (CompositionEvent) ImplementsEvent ¶
func (CompositionEvent) ImplementsEvent()
type EditEvent ¶
type EditEvent struct {
// Range specifies the range to replace with Text.
Range Range
Text string
}
An EditEvent requests an edit by an input method.
func (EditEvent) ImplementsEvent ¶
func (EditEvent) ImplementsEvent()
type Event ¶
type Event struct {
// Name of the key.
Name Name
// Code is the physical key, independent of the keyboard layout. It is
// empty for keys outside the typing area, and on platforms that don't
// report physical keys; see [Event.PhysicalCode].
Code Code
// 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
// Time is when the platform says the key changed, on a clock of its own
// that only intervals can be read from, like [pointer.Event.Time]. It is
// zero for events the platform gave no time, such as synthesized ones.
// giokit: games need to know how long a key was held, finer than a frame.
Time time.Duration
}
An Event is generated when a key is pressed. For text input use EditEvent.
func (Event) ImplementsEvent ¶
func (Event) ImplementsEvent()
func (Event) PhysicalCode ¶
PhysicalCode returns e's physical key: its Code, or, from platforms that don't report one, the key its Name has on a US layout.
type Filter ¶
type Filter struct {
// Focus is the tag that must be focused for the filter to match. It has no effect
// if it is nil.
Focus event.Tag
// Required is the set of modifiers that must be included in events matched.
Required Modifiers
// Optional is the set of modifiers that may be included in events matched.
Optional Modifiers
// Name of the key to be matched. As a special case, the empty
// Name matches every key not matched by any other filter.
//
// However, keys with platform specific side-effects, such as Tab
// and Shift-Tab for changing focus, are only matched by filters
// that specify their Name explicitly. See [gioui.org/io/input.SystemEvent].
Name Name
// Code, if set, matches the physical key instead of Name, whatever the
// keyboard layout types with it. See [Code].
Code Code
}
Filter matches any Event that matches the parameters.
func (Filter) ImplementsFilter ¶
func (Filter) ImplementsFilter()
type FocusCmd ¶
type FocusCmd struct {
// Tag is the new focus. The focus is cleared if Tag is nil, or if Tag
// has no [event.Op] references.
Tag event.Tag
}
FocusCmd requests to set or clear the keyboard focus.
func (FocusCmd) ImplementsCommand ¶
func (FocusCmd) ImplementsCommand()
type FocusDirection ¶
type FocusDirection int
const ( FocusRight FocusDirection = iota FocusLeft FocusUp FocusDown FocusForward FocusBackward )
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 FocusFilter ¶
FocusFilter matches any FocusEvent, EditEvent, SnippetEvent, or SelectionEvent with the specified target.
func (FocusFilter) ImplementsFilter ¶
func (FocusFilter) ImplementsFilter()
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. HintText // HintNumeric hints that numeric input is expected. It may activate shortcuts for 0-9, "." and ",". HintNumeric // HintEmail hints that email input is expected. It may activate shortcuts for common email characters, such as "@" and ".com". HintEmail // HintURL hints that URL input is expected. It may activate shortcuts for common URL fragments such as "/" and ".com". HintURL // HintTelephone hints that telephone number input is expected. It may activate shortcuts for 0-9, "#" and "*". HintTelephone // HintPassword hints that password input is expected. It may disable autocorrection and enable password autofill. HintPassword )
type InputHintOp ¶
InputHintOp describes the type of text expected by a tag.
func (InputHintOp) Add ¶
func (h InputHintOp) Add(o *op.Ops)
type Modifiers ¶
type Modifiers uint32
Modifiers
const ( // ModCtrl is the ctrl modifier key. ModCtrl Modifiers = 1 << iota // ModCommand is the command modifier key // found on Apple keyboards. ModCommand // ModShift is the shift modifier key. ModShift // ModAlt is the alt modifier key, or the option // key on Apple keyboards. ModAlt // ModSuper is the "logo" modifier key, often // represented by a Windows logo. ModSuper )
type MoveFocusCmd ¶
type MoveFocusCmd struct {
Dir FocusDirection
}
MoveFocusCmd moves the keyboard focus in direction Dir, as Tab and Shift+Tab do (FocusForward, FocusBackward) or by geometry (FocusUp, ...). It lets input that isn't a keyboard, such as a gamepad's d-pad, drive focus.
func (MoveFocusCmd) ImplementsCommand ¶
func (MoveFocusCmd) ImplementsCommand()
type Name ¶
type Name string
Name is the identifier for a keyboard 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.
const ( // Names for special keys. NameLeftArrow Name = "←" NameRightArrow Name = "→" NameUpArrow Name = "↑" NameDownArrow Name = "↓" NameReturn Name = "⏎" NameEnter Name = "⌤" NameEscape Name = "⎋" NameHome Name = "⇱" NameEnd Name = "⇲" NameDeleteBackward Name = "⌫" NameDeleteForward Name = "⌦" NamePageUp Name = "⇞" NamePageDown Name = "⇟" NameInsert Name = "Insert" NameTab Name = "Tab" NameSpace Name = "Space" NameCtrl Name = "Ctrl" NameShift Name = "Shift" NameAlt Name = "Alt" NameSuper Name = "Super" NameCommand Name = "⌘" NameF1 Name = "F1" NameF2 Name = "F2" NameF3 Name = "F3" NameF4 Name = "F4" NameF5 Name = "F5" NameF6 Name = "F6" NameF7 Name = "F7" NameF8 Name = "F8" NameF9 Name = "F9" NameF10 Name = "F10" NameF11 Name = "F11" NameF12 Name = "F12" NameBack Name = "Back" )
type Range ¶
Range represents a range of text, such as an editor's selection. Start and End are in runes.
type SelectionCmd ¶
type SelectionCmd struct {
Tag event.Tag
Range
Caret
// CompositionBounds is the visible bounds of the composing text, relative to
// the input handler. It is empty when there is no visible composing text.
CompositionBounds image.Rectangle
}
SelectionCmd updates the selection for an input handler.
func (SelectionCmd) ImplementsCommand ¶
func (SelectionCmd) ImplementsCommand()
type SelectionEvent ¶
type SelectionEvent Range
SelectionEvent is generated when an input method changes the selection.
func (SelectionEvent) ImplementsEvent ¶
func (SelectionEvent) ImplementsEvent()
type Snippet ¶
Snippet represents a snippet of text content used for communicating between an editor and an input method.
type SnippetCmd ¶
SnippetCmd updates the content snippet for an input handler.
func (SnippetCmd) ImplementsCommand ¶
func (SnippetCmd) ImplementsCommand()
type SnippetEvent ¶
type SnippetEvent Range
SnippetEvent is generated when the snippet range is updated by an input method.
func (SnippetEvent) ImplementsEvent ¶
func (SnippetEvent) ImplementsEvent()
type SoftKeyboardCmd ¶
type SoftKeyboardCmd struct {
Show bool
}
SoftKeyboardCmd shows or hides the on-screen keyboard, if available.
func (SoftKeyboardCmd) ImplementsCommand ¶
func (SoftKeyboardCmd) ImplementsCommand()