key

package
v4.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2022 License: Apache-2.0 Imports: 4 Imported by: 6

Documentation

Overview

Package key enumerates keystrings for use in bindings.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Down is sent when a key is pressed. It is sent both as
	// Down, and as Down + the key name.
	AnyDown = event.RegisterEvent[Event]()
	// Up is sent when a key is released. It is sent both as
	// Up, and as Up + the key name.
	AnyUp = event.RegisterEvent[Event]()
	// Held is sent when a key is held down. It is sent both as
	// Held, and as Held + the key name.
	AnyHeld = event.RegisterEvent[Event]()
)
View Source
var AllKeys = map[Code]string{}/* 119 elements not displayed */

AllKeys is the set of all defined key codes

Functions

func Down

func Down(code Code) event.EventID[Event]

func Held

func Held(code Code) event.EventID[Event]

func Up

func Up(code Code) event.EventID[Event]

Up checks

Types

type Code

type Code = key.Code

Code is the identity of a key relative to a notional "standard" keyboard. It is a straight copy of mobile package's key codes cleaned up for ease of binding in oak. See AllKeys for string mappers.

const (
	Unknown Code = 0
	A       Code = 4
	B       Code = 5
	C       Code = 6
	D       Code = 7
	E       Code = 8
	F       Code = 9
	G       Code = 10
	H       Code = 11
	I       Code = 12
	J       Code = 13
	K       Code = 14
	L       Code = 15
	M       Code = 16
	N       Code = 17
	O       Code = 18
	P       Code = 19
	Q       Code = 20
	R       Code = 21
	S       Code = 22
	T       Code = 23
	U       Code = 24
	V       Code = 25
	W       Code = 26
	X       Code = 27
	Y       Code = 28
	Z       Code = 29

	Num1 Code = 30
	Num2 Code = 31
	Num3 Code = 32
	Num4 Code = 33
	Num5 Code = 34
	Num6 Code = 35
	Num7 Code = 36
	Num8 Code = 37
	Num9 Code = 38
	Num0 Code = 39

	ReturnEnter        Code = 40
	Escape             Code = 41
	DeleteBackspace    Code = 42
	Tab                Code = 43
	Spacebar           Code = 44
	HyphenMinus        Code = 45
	EqualSign          Code = 46
	LeftSquareBracket  Code = 47
	RightSquareBracket Code = 48
	Backslash          Code = 49
	Semicolon          Code = 51
	Apostrophe         Code = 52
	GraveAccent        Code = 53
	Comma              Code = 54
	FullStop           Code = 55
	Slash              Code = 56
	CapsLock           Code = 57

	F1  Code = 58
	F2  Code = 59
	F3  Code = 60
	F4  Code = 61
	F5  Code = 62
	F6  Code = 63
	F7  Code = 64
	F8  Code = 65
	F9  Code = 66
	F10 Code = 67
	F11 Code = 68
	F12 Code = 69

	Pause         Code = 72
	Insert        Code = 73
	Home          Code = 74
	PageUp        Code = 75
	DeleteForward Code = 76
	End           Code = 77
	PageDown      Code = 78

	RightArrow Code = 79
	LeftArrow  Code = 80
	DownArrow  Code = 81
	UpArrow    Code = 82

	KeypadNumLock     Code = 83
	KeypadSlash       Code = 84
	KeypadAsterisk    Code = 85
	KeypadHyphenMinus Code = 86
	KeypadPlusSign    Code = 87
	KeypadEnter       Code = 88
	Keypad1           Code = 89
	Keypad2           Code = 90
	Keypad3           Code = 91
	Keypad4           Code = 92
	Keypad5           Code = 93
	Keypad6           Code = 94
	Keypad7           Code = 95
	Keypad8           Code = 96
	Keypad9           Code = 97
	Keypad0           Code = 98
	KeypadFullStop    Code = 99
	KeypadEqualSign   Code = 103

	F13 Code = 104
	F14 Code = 105
	F15 Code = 106
	F16 Code = 107
	F17 Code = 108
	F18 Code = 109
	F19 Code = 110
	F20 Code = 111
	F21 Code = 112
	F22 Code = 113
	F23 Code = 114
	F24 Code = 115

	Help Code = 117

	Mute       Code = 127
	VolumeUp   Code = 128
	VolumeDown Code = 129

	LeftControl  Code = 224
	LeftShift    Code = 225
	LeftAlt      Code = 226
	LeftGUI      Code = 227
	RightControl Code = 228
	RightShift   Code = 229
	RightAlt     Code = 230
	RightGUI     Code = 231
	Compose      Code = 0x10000
)

type Direction

type Direction = key.Direction
const (
	DirNone    Direction = 0
	DirPress   Direction = 1
	DirRelease Direction = 2
)

type Event

type Event key.Event

An Event is sent as the payload for all key bindings.

type Modifiers

type Modifiers = key.Modifiers
const (
	ModShift   Modifiers = 1 << 0
	ModControl Modifiers = 1 << 1
	ModAlt     Modifiers = 1 << 2
	ModMeta    Modifiers = 1 << 3 // called "Command" on OS X
)

type State

type State struct {
	// contains filtered or unexported fields
}

A State tracks what keys of a keyboard are currently pressed and for how long they have been pressed if they are held down.

func NewState

func NewState() State

NewState creates a state object for tracking keyboard state.

func (*State) IsDown

func (ks *State) IsDown(key Code) (k bool)

IsDown returns whether a key is held down

func (*State) IsHeld

func (ks *State) IsHeld(key Code) (k bool, d time.Duration)

IsHeld returns whether a key is held down, and for how long it has been held.

func (*State) SetDown

func (ks *State) SetDown(key Code)

SetDown will cause later IsDown calls to report true for the given key. This is called internally when events are sent from the real keyboard and mouse. Calling this can interrupt real input or cause unintended behavior and should be done cautiously.

func (*State) SetUp

func (ks *State) SetUp(key Code)

SetUp will cause later IsDown calls to report false for the given key. This is called internally when events are sent from the real keyboard and mouse. Calling this can interrupt real input or cause unintended behavior and should be done cautiously.

Jump to

Keyboard shortcuts

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