key

package
v1.3.23 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2023 License: BSD-3-Clause Imports: 8 Imported by: 12

Documentation

Overview

Package key defines an event for physical keyboard keys, for the GoGi 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 KiT_Actions = kit.Enums.AddEnum(ActionsN, kit.NotBitFlag, nil)
View Source
var KiT_Modifiers = kit.Enums.AddEnum(ModifiersN, kit.BitFlag, nil)

Functions

func CodeIsModifier

func CodeIsModifier(c Codes) bool

CodeIsModifier returns true if given code is a modifier key

func HasAllModifierBits

func HasAllModifierBits(modBits int32, mods ...Modifiers) bool

HasAllModifiersBits tests whether all of given modifier(s) bits were set

func HasAnyModifierBits

func HasAnyModifierBits(modBits int32, mods ...Modifiers) bool

HasAnyModifierBits tests whether any of given modifier(s) bits were set

func ModsFmString

func ModsFmString(cs string) (int32, string)

ModsFmString returns the modifiers corresponding to given string and the remainder of the string after modifiers have been stripped

func ModsString

func ModsString(mods int32) string

ModsString returns the string representation of the modifiers

func SetModifierBits

func SetModifierBits(modBits *int32, mods ...Modifiers)

SetModifierBits sets the bitflags based on a list of key.Modifiers

Types

type Actions

type Actions int32

Actions is the action taken on the key

const (
	NoAction Actions = iota
	Press
	Release

	ActionsN
)

func (*Actions) FromString

func (i *Actions) FromString(s string) error

func (Actions) String

func (i Actions) String() string

type Chord

type Chord string

key.Chord represents the key chord associated with a given key function -- it is linked to the KeyChordEdit in the giv ValueView system so you can just type keys to set key chords.

func (Chord) Decode

func (ch Chord) Decode() (r rune, mods int32, err error)

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

func (Chord) OSShortcut

func (ch Chord) OSShortcut() Chord

OSShortcut translates Command into either Control or Meta depending on platform

func (Chord) Shortcut

func (ch Chord) Shortcut() string

Shortcut transforms chord string into short form suitable for display to users

type ChordEvent

type ChordEvent struct {
	Event
}

key.ChordEvent reports events that are generated only on keyboard release, and that include the full chord information about all the modifier keys that were present when a non-modifier key was released -- these are generally appropriate for most uses

func (*ChordEvent) Type

func (ev *ChordEvent) Type() oswin.EventType

type Codes

type Codes uint32

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
	CodeDeleteBackspace    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
	CodeDeleteForward 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.

func (Codes) String

func (i Codes) String() string

type Event

type Event struct {
	oswin.EventBase

	// Rune is the meaning of the key event as determined by the
	// operating system. The mapping is determined by system-dependent
	// current layout, modifiers, lock-states, etc.
	//
	// If non-negative, it is a Unicode codepoint: pressing the 'a' key
	// generates different Runes 'a' or 'A' (but the same Code) depending on
	// the state of the shift key.
	//
	// If -1, the key does not generate a Unicode codepoint. To distinguish
	// them, look at Code.
	Rune rune

	// Code is the identity of the physical key relative to a notional
	// "standard" keyboard, independent of current layout, modifiers,
	// lock-states, etc
	//
	// For standard key codes, its value matches USB HID key codes.
	// Compare its value to uint32-typed constants in this package, such
	// as CodeLeftShift and CodeEscape.
	//
	// Pressing the regular '2' key and number-pad '2' key (with Num-Lock)
	// generate different Codes (but the same Rune).
	Code Codes

	// Modifiers is bitflags representing a set of modifier keys: ModShift,
	// ModAlt, etc. -- bit positions are key.Modifiers
	Modifiers int32

	// Action is the key action taken: Press, Release, or None (for key repeats).
	Action Actions
}

key.Event is a low-level immediately-generated key event, tracking press and release of keys -- suitable for fine-grained tracking of key events -- see also key.ChordEvent for events that are generated only on key press, and that include the full chord information about all the modifier keys that were present when a non-modifier key was released

func (*Event) Chord

func (e *Event) Chord() Chord

Chord 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 (*Event) HasAllModifier

func (e *Event) HasAllModifier(mods ...Modifiers) bool

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

func (*Event) HasAnyModifier

func (e *Event) HasAnyModifier(mods ...Modifiers) bool

HasAnyModifier tests whether any of given modifier(s) were set

func (*Event) HasPos

func (ev *Event) HasPos() bool

func (*Event) OnFocus

func (ev *Event) OnFocus() bool

func (*Event) Pos

func (ev *Event) Pos() image.Point

func (*Event) SetModifiers

func (e *Event) SetModifiers(mods ...Modifiers)

SetModifiers sets the bitflags based on a list of key.Modifiers

func (*Event) String

func (ev *Event) String() string

func (*Event) Type

func (ev *Event) Type() oswin.EventType

type Modifiers

type Modifiers int32

Modifiers are used as bitflags representing a set of modifier keys -- see SetModifiers method

const (
	Shift Modifiers = iota
	Control
	Alt
	Meta // called "Command" on OS X

	ModifiersN
)

func (*Modifiers) FromString

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

func (Modifiers) String

func (i Modifiers) String() string

Jump to

Keyboard shortcuts

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