input

package
v0.0.0-...-55a4dde Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	/*
		DeviceTypeKeyboard keys will be where the hardware says they are
		e.g. "W S A D" will always have the same physical location
		but may not be labeled "W S A D".
	*/
	DeviceTypeKeyboard = "keyboard"

	/*
		DeviceTypeMouse represents a typical 5 button plus scrollwheel mouse.
		MouseMotion coordinates would be relative to the drawable surface where
		top left is {0, 0, 0} and bottom right is {w, h, 0}.
	*/
	DeviceTypeMouse = "mouse"
)
View Source
const (
	ScanValue = 1 << iota
	ScanAxis
	ScanCoords
)

Variables

This section is empty.

Functions

func RegisterDevice

func RegisterDevice(d Device)

RegisterDevice registers a device that can be obetained with the GetDevice* functions. The instance must be valid even if the device disconnected and shall receive future events when the device reconnected.

Whether the instance refers to the same physical device on reconnect is a implementation detail.

Unplugging Controller A and plugging in Controller B of the same type, may send events to the instance of the unplugged Controller A even tho they are not the same physical device. However if the player then plugs Controller A, it must use another unplugged instance or register a new instance.

func Scan

func Scan(mask ScanMask) (device Device, action DeviceAction)

Scan returns the device and the action, using mask to filter action types, that had a DeviceAction triggered this frame or nil and 0.

This is useful for input mapping without having to specifically code to support every device type.

As this is only meant to be used for key mapping, we can assume there will only be one input a frame and that speed isn't too important so just check everything.

Types

type Axis

type Axis struct {
	gmath.Vector3f64
}

Axis represents a 3D vector action such as mouse or analog stick movement.

type Coords

type Coords struct {
	gmath.Point3f64
}

Coords represents a 3D position action such as mouse or tap position.

type Device

type Device interface {
	/*
		Returns a string used to identify the device type. If type is one of the
		predefined DeviceType* strings then the implementation must follow the
		documentation for said type and its' defined DeviceAction codes.
	*/
	Type() string

	/*
		Returns the current frame's state of the action as either a input.Value,
		input.Axis or a input.Coords.
		Returns nil if DeviceAction is invalid.

		On device disconnect, the device should act as if the player stopped
		interacting with said device. For Value and Axis actions this means they
		are in the default state. For Coords this means they are frozen in place.
		StateDeltaFor and ActionEndedFor should be triggered as expected
		for the state change.

		If each space separated number is the value returned a frame,
		then pressing a button would go:
		default - pressed - released - default
		0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0
	*/
	StateFor(DeviceAction) State

	/*
		Returns the delta state of the current and previous frame for the action
		as either a input.Value or a input.Axis. Does not return a input.Coords
		as the delta of 2 input.Coords would be a input.Axis (vector).
		Returns nil if DeviceAction is invalid.

		On device disconnect, the device should act as if the player stopped
		interacting with said device. For buttons that were pressed the frame
		previous to the disconnect, the delta would reflect a button release.
		The delta of Coords actions would be zero as they are frozen in place.
		While the delta of Axis actions would reflect the return to the default state.

		If each space separated number is the value returned a frame,
		then pressing a button would go:
		default - pressed - released - default
		0 0 0 0 0 1 0 0 0 0 -1 0 0 0 0 0 0 0 0
	*/
	StateDeltaFor(DeviceAction) StateDelta

	/*
		Returns true if this is the first frame a action started,
		Returns false if DeviceAction is invalid.

		On device disconnect, the device should act as if the player stopped
		interacting with said device, nothing should return true.

		If each space separated number is the value returned a frame,
		then pressing a button would go:
		default - pressed - released - default
		0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
	*/
	ActionStartedFor(DeviceAction) bool

	/*
		Returns true if this is the first frame a action stopped,
		Returns false if DeviceAction is invalid.

		On device disconnect, the device should act as if the player stopped
		interacting with said device. All actions that were started the frame
		previous to the disconnect shall be considered ended.

		If each space separated number is the value returned a frame,
		then pressing a button would go:
		default - pressed - released - default
		0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
	*/
	ActionEndedFor(DeviceAction) bool
}

func DeviceOfType

func DeviceOfType(t string) Device

DeviceOfType retruns the first found device of the given type or nil.

func DevicesOfType

func DevicesOfType(t string) []Device

DevicesOfType retruns a copy of the slice containing all the devices of a given type or nil.

type DeviceAction

type DeviceAction uint8
const (
	KeyA                   DeviceAction = 4
	KeyB                   DeviceAction = 5
	KeyC                   DeviceAction = 6
	KeyD                   DeviceAction = 7
	KeyE                   DeviceAction = 8
	KeyF                   DeviceAction = 9
	KeyG                   DeviceAction = 10
	KeyH                   DeviceAction = 11
	KeyI                   DeviceAction = 12
	KeyJ                   DeviceAction = 13
	KeyK                   DeviceAction = 14
	KeyL                   DeviceAction = 15
	KeyM                   DeviceAction = 16
	KeyN                   DeviceAction = 17
	KeyO                   DeviceAction = 18
	KeyP                   DeviceAction = 19
	KeyQ                   DeviceAction = 20
	KeyR                   DeviceAction = 21
	KeyS                   DeviceAction = 22
	KeyT                   DeviceAction = 23
	KeyU                   DeviceAction = 24
	KeyV                   DeviceAction = 25
	KeyW                   DeviceAction = 26
	KeyX                   DeviceAction = 27
	KeyY                   DeviceAction = 28
	KeyZ                   DeviceAction = 29
	Key1                   DeviceAction = 30
	Key2                   DeviceAction = 31
	Key3                   DeviceAction = 32
	Key4                   DeviceAction = 33
	Key5                   DeviceAction = 34
	Key6                   DeviceAction = 35
	Key7                   DeviceAction = 36
	Key8                   DeviceAction = 37
	Key9                   DeviceAction = 38
	Key0                   DeviceAction = 39
	KeyEnter               DeviceAction = 40
	KeyEscape              DeviceAction = 41
	KeyBackspace           DeviceAction = 42
	KeyTab                 DeviceAction = 43
	KeySpacebar            DeviceAction = 44
	KeyMinus               DeviceAction = 45
	KeyEquals              DeviceAction = 46
	KeyLeftBracket         DeviceAction = 47
	KeyRightBracket        DeviceAction = 48
	KeyBackslash           DeviceAction = 49
	KeyNonUSHash           DeviceAction = 50
	KeySemicolon           DeviceAction = 51
	KeyApostrophe          DeviceAction = 52
	KeyGrave               DeviceAction = 53
	KeyComma               DeviceAction = 54
	KeyPeriod              DeviceAction = 55
	KeySlash               DeviceAction = 56
	KeyCapsLock            DeviceAction = 57
	KeyF1                  DeviceAction = 58
	KeyF2                  DeviceAction = 59
	KeyF3                  DeviceAction = 60
	KeyF4                  DeviceAction = 61
	KeyF5                  DeviceAction = 62
	KeyF6                  DeviceAction = 63
	KeyF7                  DeviceAction = 64
	KeyF8                  DeviceAction = 65
	KeyF9                  DeviceAction = 66
	KeyF10                 DeviceAction = 67
	KeyF11                 DeviceAction = 68
	KeyF12                 DeviceAction = 69
	KeyPrintScreen         DeviceAction = 70
	KeyScrollLock          DeviceAction = 71
	KeyPause               DeviceAction = 72
	KeyInsert              DeviceAction = 73
	KeyHome                DeviceAction = 74
	KeyPageUp              DeviceAction = 75
	KeyDelete              DeviceAction = 76
	KeyEnd                 DeviceAction = 77
	KeyPageDown            DeviceAction = 78
	KeyRight               DeviceAction = 79
	KeyLeft                DeviceAction = 80
	KeyDown                DeviceAction = 81
	KeyUp                  DeviceAction = 82
	KeyNumLock             DeviceAction = 83
	KeyKPDivide            DeviceAction = 84
	KeyKPMultiply          DeviceAction = 85
	KeyKPMinus             DeviceAction = 86
	KeyKPPlus              DeviceAction = 87
	KeyKPEnter             DeviceAction = 88
	KeyKP1                 DeviceAction = 89
	KeyKP2                 DeviceAction = 90
	KeyKP3                 DeviceAction = 91
	KeyKP4                 DeviceAction = 92
	KeyKP5                 DeviceAction = 93
	KeyKP6                 DeviceAction = 94
	KeyKP7                 DeviceAction = 95
	KeyKP8                 DeviceAction = 96
	KeyKP9                 DeviceAction = 97
	KeyKP0                 DeviceAction = 98
	KeyKPPeriod            DeviceAction = 99
	KeyNonUSBackslash      DeviceAction = 100
	KeyApplication         DeviceAction = 101
	KeyPower               DeviceAction = 102
	KeyKPEquals            DeviceAction = 103
	KeyF13                 DeviceAction = 104
	KeyF14                 DeviceAction = 105
	KeyF15                 DeviceAction = 106
	KeyF16                 DeviceAction = 107
	KeyF17                 DeviceAction = 108
	KeyF18                 DeviceAction = 109
	KeyF19                 DeviceAction = 110
	KeyF20                 DeviceAction = 111
	KeyF21                 DeviceAction = 112
	KeyF22                 DeviceAction = 113
	KeyF23                 DeviceAction = 114
	KeyF24                 DeviceAction = 115
	KeyExecute             DeviceAction = 116
	KeyHelp                DeviceAction = 117
	KeyMenu                DeviceAction = 118
	KeySelect              DeviceAction = 119
	KeyStop                DeviceAction = 120
	KeyAgain               DeviceAction = 121
	KeyUndo                DeviceAction = 122
	KeyCut                 DeviceAction = 123
	KeyCopy                DeviceAction = 124
	KeyPaste               DeviceAction = 125
	KeyFind                DeviceAction = 126
	KeyMute                DeviceAction = 127
	KeyVolumeUp            DeviceAction = 128
	KeyVolumeDown          DeviceAction = 129
	KeyKPComma             DeviceAction = 133
	KeyKPEqualsAS400       DeviceAction = 134
	KeyInternational1      DeviceAction = 135
	KeyInternational2      DeviceAction = 136
	KeyInternational3      DeviceAction = 137
	KeyInternational4      DeviceAction = 138
	KeyInternational5      DeviceAction = 139
	KeyInternational6      DeviceAction = 140
	KeyInternational7      DeviceAction = 141
	KeyInternational8      DeviceAction = 142
	KeyInternational9      DeviceAction = 143
	KeyLang1               DeviceAction = 144
	KeyLang2               DeviceAction = 145
	KeyLang3               DeviceAction = 146
	KeyLang4               DeviceAction = 147
	KeyLang5               DeviceAction = 148
	KeyLang6               DeviceAction = 149
	KeyLang7               DeviceAction = 150
	KeyLang8               DeviceAction = 151
	KeyLang9               DeviceAction = 152
	KeyAltErase            DeviceAction = 153
	KeySysReq              DeviceAction = 154
	KeyCancel              DeviceAction = 155
	KeyClear               DeviceAction = 156
	KeyPrior               DeviceAction = 157
	KeyReturn              DeviceAction = 158
	KeySeparator           DeviceAction = 159
	KeyOut                 DeviceAction = 160
	KeyOper                DeviceAction = 161
	KeyClearAgain          DeviceAction = 162
	KeyCrSel               DeviceAction = 163
	KeyExSel               DeviceAction = 164
	KeyKP00                DeviceAction = 176
	KeyKP000               DeviceAction = 177
	KeyThousandsSeparator  DeviceAction = 178
	KeyDecimalSeparator    DeviceAction = 179
	KeyCurrencyUnit        DeviceAction = 180
	KeyCurrencySubmit      DeviceAction = 181
	KeyKPLeftParentheses   DeviceAction = 182
	KeyKPRightParentheses  DeviceAction = 183
	KeyKPLeftBrace         DeviceAction = 184
	KeyKPRightBrace        DeviceAction = 185
	KeyKPTab               DeviceAction = 186
	KeyKPBackspace         DeviceAction = 187
	KeyKPA                 DeviceAction = 188
	KeyKPB                 DeviceAction = 189
	KeyKPC                 DeviceAction = 190
	KeyKPD                 DeviceAction = 191
	KeyKPE                 DeviceAction = 192
	KeyKPF                 DeviceAction = 193
	KeyKPXOR               DeviceAction = 194
	KeyKPPower             DeviceAction = 195
	KeyKPPercent           DeviceAction = 196
	KeyKPLess              DeviceAction = 197
	KeyKPGreater           DeviceAction = 198
	KeyKPAmpersand         DeviceAction = 199
	KeyKPDoubleAmpersand   DeviceAction = 200
	KeyKPVerticalBar       DeviceAction = 201
	KeyKPDoubleVerticalBar DeviceAction = 202
	KeyKPColon             DeviceAction = 203
	KeyKPHash              DeviceAction = 204
	KeyKPSpace             DeviceAction = 205
	KeyKPAt                DeviceAction = 206
	KeyKPExclamation       DeviceAction = 207
	KeyKPMemStore          DeviceAction = 208
	KeyKPMemRecall         DeviceAction = 209
	KeyKPMemClear          DeviceAction = 210
	KeyKPMemAdd            DeviceAction = 211
	KeyKPMemSubtract       DeviceAction = 212
	KeyKPMemMultiply       DeviceAction = 213
	KeyKPMemDivide         DeviceAction = 214
	KeyKPPlusMinus         DeviceAction = 215
	KeyKPClear             DeviceAction = 216
	KeyKPClearEntry        DeviceAction = 217
	KeyKPBinary            DeviceAction = 218
	KeyKPOctal             DeviceAction = 219
	KeyKPDecimal           DeviceAction = 220
	KeyKPHexadecimal       DeviceAction = 221
	KeyLeftCtrl            DeviceAction = 224
	KeyLeftShift           DeviceAction = 225
	KeyLeftAlt             DeviceAction = 226
	KeyLeftGUI             DeviceAction = 227
	KeyRightCtrl           DeviceAction = 228
	KeyRightShift          DeviceAction = 229
	KeyRightAlt            DeviceAction = 230
	KeyRightGUI            DeviceAction = 231
)

Key codes of keys on the keyboard as defined in the USB HID Usage Tables https://usb.org/document-library/hid-usage-tables-122

const (
	MouseLeft DeviceAction
	MouseMiddle
	MouseRight
	MouseBack
	MouseForward
	MouseWheel
	MouseMotion
)

type ScanMask

type ScanMask uint8

ScanMask represents a bitmask of the types of input events to scan for.

type State

type State interface {
	// contains filtered or unexported methods
}

type StateDelta

type StateDelta interface {
	// contains filtered or unexported methods
}

type Value

type Value float32

Value represents a linear action such as a button or analog trigger. For buttons this is either a 0 or a 1 or a delta of -1. For analog actions this would be between 0.0 and 1.0 inclusive.

Jump to

Keyboard shortcuts

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