Documentation ¶
Overview ¶
Package key defines an event for physical keyboard keys, for the Cogent Core GUI system.
On-screen software keyboards do not send key events.
Index ¶
- Variables
- func CodeIsModifier(c Codes) bool
- func HasAllModifiers(flags Modifiers, mods ...enums.BitFlag) bool
- func HasAnyModifier(flags Modifiers, mods ...enums.BitFlag) bool
- type Chord
- type Codes
- type Modifiers
- func (i Modifiers) BitIndexString() string
- func (i Modifiers) Desc() string
- func (i *Modifiers) HasFlag(f enums.BitFlag) bool
- func (i Modifiers) Int64() int64
- func (i Modifiers) MarshalText() ([]byte, error)
- func (mo Modifiers) ModifiersString() string
- func (i *Modifiers) SetFlag(on bool, f ...enums.BitFlag)
- func (i *Modifiers) SetInt64(in int64)
- func (i *Modifiers) SetString(s string) error
- func (i *Modifiers) SetStringOr(s string) error
- func (i Modifiers) String() string
- func (i *Modifiers) UnmarshalText(text []byte) error
- func (i Modifiers) Values() []enums.Enum
Constants ¶
This section is empty.
Variables ¶
var CodeRuneMap = map[Codes]rune{ CodeA: 'A', CodeB: 'B', CodeC: 'C', CodeD: 'D', CodeE: 'E', CodeF: 'F', CodeG: 'G', CodeH: 'H', CodeI: 'I', CodeJ: 'J', CodeK: 'K', CodeL: 'L', CodeM: 'M', CodeN: 'N', CodeO: 'O', CodeP: 'P', CodeQ: 'Q', CodeR: 'R', CodeS: 'S', CodeT: 'T', CodeU: 'U', CodeV: 'V', CodeW: 'W', CodeX: 'X', CodeY: 'Y', CodeZ: 'Z', Code1: '1', Code2: '2', Code3: '3', Code4: '4', Code5: '5', Code6: '6', Code7: '7', Code8: '8', Code9: '9', Code0: '0', CodeTab: '\t', CodeSpacebar: ' ', CodeHyphenMinus: '-', CodeEqualSign: '=', CodeLeftSquareBracket: '[', CodeRightSquareBracket: ']', CodeBackslash: '\\', CodeSemicolon: ';', CodeApostrophe: '\'', CodeGraveAccent: '`', CodeComma: ',', CodeFullStop: '.', CodeSlash: '/', CodeKeypadSlash: '/', CodeKeypadAsterisk: '*', CodeKeypadHyphenMinus: '-', CodeKeypadPlusSign: '+', CodeKeypadFullStop: '.', CodeKeypadEqualSign: '=', }
var SystemPlatform string
SystemPlatform is the string version of cogentcore.org/core/system.App.SystemPlatform, which is set by system during initialization so that this package can conditionalize shortcut formatting based on the underlying system platform without import cycles.
Functions ¶
func CodeIsModifier ¶
CodeIsModifier returns true if given code is a modifier key
func HasAllModifiers ¶
HasAllModifiers tests whether all of given modifier(s) were set
Types ¶
type Chord ¶
type Chord string
Chord represents the key chord associated with a given key function; it is linked to the cogentcore.org/core/core.KeyChordValue so you can just type keys to set key chords.
func NewChord ¶
NewChord returns a string representation of the keyboard event suitable for keyboard function maps, etc. Printable runes are sent directly, and non-printable ones are converted to their corresponding code names without the "Code" prefix.
func (Chord) Chords ¶ added in v0.2.0
Chords returns the multiple keys represented in a multi-key sequence
func (Chord) IsMulti ¶ added in v0.2.0
IsMulti returns true if the Chord represents a multi-key sequence
func (Chord) Label ¶ added in v0.0.8
Label transforms the chord string into a short form suitable for display to users.
func (Chord) PlatformChord ¶ added in v0.0.8
PlatformChord translates Command into either Control or Meta depending on the platform
type Codes ¶
type Codes uint32 //enums:enum -trim-prefix Code
Codes is the identity of a key relative to a notional "standard" keyboard.
const ( CodeUnknown Codes = 0 CodeA Codes = 4 CodeB Codes = 5 CodeC Codes = 6 CodeD Codes = 7 CodeE Codes = 8 CodeF Codes = 9 CodeG Codes = 10 CodeH Codes = 11 CodeI Codes = 12 CodeJ Codes = 13 CodeK Codes = 14 CodeL Codes = 15 CodeM Codes = 16 CodeN Codes = 17 CodeO Codes = 18 CodeP Codes = 19 CodeQ Codes = 20 CodeR Codes = 21 CodeS Codes = 22 CodeT Codes = 23 CodeU Codes = 24 CodeV Codes = 25 CodeW Codes = 26 CodeX Codes = 27 CodeY Codes = 28 CodeZ Codes = 29 Code1 Codes = 30 Code2 Codes = 31 Code3 Codes = 32 Code4 Codes = 33 Code5 Codes = 34 Code6 Codes = 35 Code7 Codes = 36 Code8 Codes = 37 Code9 Codes = 38 Code0 Codes = 39 CodeReturnEnter Codes = 40 CodeEscape Codes = 41 CodeBackspace Codes = 42 CodeTab Codes = 43 CodeSpacebar Codes = 44 CodeHyphenMinus Codes = 45 // - CodeEqualSign Codes = 46 // = CodeLeftSquareBracket Codes = 47 // [ CodeRightSquareBracket Codes = 48 // ] CodeBackslash Codes = 49 // \ CodeSemicolon Codes = 51 // ; CodeApostrophe Codes = 52 // ' CodeGraveAccent Codes = 53 // ` CodeComma Codes = 54 // , CodeFullStop Codes = 55 // . CodeSlash Codes = 56 // / CodeCapsLock Codes = 57 CodeF1 Codes = 58 CodeF2 Codes = 59 CodeF3 Codes = 60 CodeF4 Codes = 61 CodeF5 Codes = 62 CodeF6 Codes = 63 CodeF7 Codes = 64 CodeF8 Codes = 65 CodeF9 Codes = 66 CodeF10 Codes = 67 CodeF11 Codes = 68 CodeF12 Codes = 69 CodePause Codes = 72 CodeInsert Codes = 73 CodeHome Codes = 74 CodePageUp Codes = 75 CodeDelete Codes = 76 CodeEnd Codes = 77 CodePageDown Codes = 78 CodeRightArrow Codes = 79 CodeLeftArrow Codes = 80 CodeDownArrow Codes = 81 CodeUpArrow Codes = 82 CodeKeypadNumLock Codes = 83 CodeKeypadSlash Codes = 84 CodeKeypadAsterisk Codes = 85 // * CodeKeypadHyphenMinus Codes = 86 CodeKeypadPlusSign Codes = 87 // + CodeKeypadEnter Codes = 88 CodeKeypad1 Codes = 89 CodeKeypad2 Codes = 90 CodeKeypad3 Codes = 91 CodeKeypad4 Codes = 92 CodeKeypad5 Codes = 93 CodeKeypad6 Codes = 94 CodeKeypad7 Codes = 95 CodeKeypad8 Codes = 96 CodeKeypad9 Codes = 97 CodeKeypad0 Codes = 98 CodeKeypadFullStop Codes = 99 CodeKeypadEqualSign Codes = 103 CodeF13 Codes = 104 CodeF14 Codes = 105 CodeF15 Codes = 106 CodeF16 Codes = 107 CodeF17 Codes = 108 CodeF18 Codes = 109 CodeF19 Codes = 110 CodeF20 Codes = 111 CodeF21 Codes = 112 CodeF22 Codes = 113 CodeF23 Codes = 114 CodeF24 Codes = 115 CodeHelp Codes = 117 CodeMute Codes = 127 CodeVolumeUp Codes = 128 CodeVolumeDown Codes = 129 CodeLeftControl Codes = 224 CodeLeftShift Codes = 225 CodeLeftAlt Codes = 226 CodeLeftMeta Codes = 227 // Command on mac, win key on windows, ? on linux CodeRightControl Codes = 228 CodeRightShift Codes = 229 CodeRightAlt Codes = 230 CodeRightMeta Codes = 231 // CodeCompose is the Code for a compose key, sometimes called a multi key, // used to input non-ASCII characters such as ñ being composed of n and ~. // // See https://en.wikipedia.org/wiki/Compose_key CodeCompose Codes = 0x10000 )
Physical key codes.
For standard key codes, its value matches USB HID key codes. TODO: add missing codes.
const CodesN Codes = 65537
CodesN is the highest valid value for type Codes, plus one.
func CodesValues ¶
func CodesValues() []Codes
CodesValues returns all possible values for the type Codes.
func (Codes) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Codes) SetString ¶
SetString sets the Codes value from its string representation, and returns an error if the string is invalid.
func (*Codes) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Modifiers ¶
type Modifiers int64 //enums:bitflag
Modifiers are used as bitflags representing a set of modifier keys.
const ModifiersN Modifiers = 4
ModifiersN is the highest valid value for type Modifiers, plus one.
func ModifiersFromString ¶ added in v0.1.1
ModifiersFromString returns the modifiers corresponding to given string and the remainder of the string after modifiers have been stripped
func ModifiersValues ¶
func ModifiersValues() []Modifiers
ModifiersValues returns all possible values for the type Modifiers.
func (Modifiers) BitIndexString ¶
BitIndexString returns the string representation of this Modifiers value if it is a bit index value (typically an enum constant), and not an actual bit flag value.
func (Modifiers) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (Modifiers) ModifiersString ¶ added in v0.1.1
ModifiersString returns the string representation of the modifiers using plus symbols as seperators. The order is given by Modifiers order: Control, Meta, Alt, Shift.
func (*Modifiers) SetFlag ¶
SetFlag sets the value of the given flags in these flags to the given value.
func (*Modifiers) SetString ¶
SetString sets the Modifiers value from its string representation, and returns an error if the string is invalid.
func (*Modifiers) SetStringOr ¶
SetStringOr sets the Modifiers value from its string representation while preserving any bit flags already set, and returns an error if the string is invalid.
func (*Modifiers) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.