key

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2024 License: BSD-3-Clause Imports: 5 Imported by: 4

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

Constants

This section is empty.

Variables

View Source
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:   '=',
}
View Source
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

func CodeIsModifier(c Codes) bool

CodeIsModifier returns true if given code is a modifier key

func HasAllModifiers

func HasAllModifiers(flags Modifiers, mods ...enums.BitFlag) bool

HasAllModifiers tests whether all of given modifier(s) were set

func HasAnyModifier

func HasAnyModifier(flags Modifiers, mods ...enums.BitFlag) bool

HasAnyModifier tests whether any 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

func NewChord(rn rune, code Codes, mods Modifiers) Chord

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

func (ch Chord) Chords() []Chord

Chords returns the multiple keys represented in a multi-key sequence

func (Chord) Decode

func (ch Chord) Decode() (r rune, code Codes, mods Modifiers, err error)

Decode decodes a chord string into rune and modifiers (set as bit flags)

func (Chord) IsMulti added in v0.2.0

func (ch Chord) IsMulti() bool

IsMulti returns true if the Chord represents a multi-key sequence

func (Chord) Label added in v0.0.8

func (ch Chord) Label() string

Label transforms the chord string into a short form suitable for display to users.

func (Chord) PlatformChord added in v0.0.8

func (ch Chord) PlatformChord() Chord

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) Desc

func (i Codes) Desc() string

Desc returns the description of the Codes value.

func (Codes) Int64

func (i Codes) Int64() int64

Int64 returns the Codes value as an int64.

func (Codes) MarshalText

func (i Codes) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Codes) SetInt64

func (i *Codes) SetInt64(in int64)

SetInt64 sets the Codes value from an int64.

func (*Codes) SetString

func (i *Codes) SetString(s string) error

SetString sets the Codes value from its string representation, and returns an error if the string is invalid.

func (Codes) String

func (i Codes) String() string

String returns the string representation of this Codes value.

func (*Codes) UnmarshalText

func (i *Codes) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Codes) Values

func (i Codes) Values() []enums.Enum

Values returns all possible values for the type Codes.

type Modifiers

type Modifiers int64 //enums:bitflag

Modifiers are used as bitflags representing a set of modifier keys.

const (
	// Control is the "Control" (Ctrl) key.
	Control Modifiers = iota

	// Meta is the system meta key (the "Command" key on macOS
	// and the Windows key on Windows).
	Meta

	// Alt is the "Alt" ("Option" on macOS) key.
	Alt

	// Shift is the "Shift" key.
	Shift
)
const ModifiersN Modifiers = 4

ModifiersN is the highest valid value for type Modifiers, plus one.

func ModifiersFromString added in v0.1.1

func ModifiersFromString(cs string) (Modifiers, string)

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

func (i Modifiers) BitIndexString() string

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) Desc

func (i Modifiers) Desc() string

Desc returns the description of the Modifiers value.

func (Modifiers) HasFlag

func (i Modifiers) HasFlag(f enums.BitFlag) bool

HasFlag returns whether these bit flags have the given bit flag set.

func (Modifiers) Int64

func (i Modifiers) Int64() int64

Int64 returns the Modifiers value as an int64.

func (Modifiers) MarshalText

func (i Modifiers) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (Modifiers) ModifiersString added in v0.1.1

func (mo Modifiers) ModifiersString() string

ModifiersString returns the string representation of the modifiers using plus symbols as seperators.

func (*Modifiers) SetFlag

func (i *Modifiers) SetFlag(on bool, f ...enums.BitFlag)

SetFlag sets the value of the given flags in these flags to the given value.

func (*Modifiers) SetInt64

func (i *Modifiers) SetInt64(in int64)

SetInt64 sets the Modifiers value from an int64.

func (*Modifiers) SetString

func (i *Modifiers) SetString(s string) error

SetString sets the Modifiers value from its string representation, and returns an error if the string is invalid.

func (*Modifiers) SetStringOr

func (i *Modifiers) SetStringOr(s string) error

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) String

func (i Modifiers) String() string

String returns the string representation of this Modifiers value.

func (*Modifiers) UnmarshalText

func (i *Modifiers) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Modifiers) Values

func (i Modifiers) Values() []enums.Enum

Values returns all possible values for the type Modifiers.

Jump to

Keyboard shortcuts

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