Documentation
¶
Index ¶
- Constants
- Variables
- type Binding
- type DeviceId
- type DeviceIndex
- type DeviceType
- type Event
- type EventDispatcher
- type EventGroup
- func (eg *EventGroup) FindEvent(id KeyId) (Event, bool)
- func (eg *EventGroup) GetMousePosition() (int, int)
- func (eg *EventGroup) HasMousePosition() bool
- func (eg *EventGroup) IsMouseMove() bool
- func (eg *EventGroup) IsPressed(id KeyId) bool
- func (eg *EventGroup) IsReleased(id KeyId) bool
- func (eg *EventGroup) PrimaryEvent() Event
- func (eg *EventGroup) SetMousePosition(x, y int)
- func (eg EventGroup) String() string
- type Input
- func (input *Input) BindDerivedKey(name string, bindings ...Binding) Key
- func (input *Input) GetKeyById(id KeyId) Key
- func (input *Input) GetKeyByParts(key_index KeyIndex, device_type DeviceType, device_index DeviceIndex) Key
- func (input *Input) MakeBinding(primary KeyId, modifiers []KeyId, down []bool) Binding
- func (input *Input) RegisterEventListener(listener Listener)
- func (input *Input) SetLogger(logger glog.Logger)
- func (input *Input) Think(t int64, os_events []OsEvent) []EventGroup
- type Key
- type KeyId
- type KeyIndex
- type Listener
- type MousePosition
- type OsEvent
Constants ¶
const ( AnyKey KeyIndex = 1 Space = 32 Backspace = 8 Tab = 9 Return = 13 Escape = 27 KeyA = 97 KeyB = 98 KeyC = 99 KeyD = 100 KeyE = 101 KeyF = 102 KeyG = 103 KeyH = 104 KeyI = 105 KeyJ = 106 KeyK = 107 KeyL = 108 KeyM = 109 KeyN = 110 KeyO = 111 KeyP = 112 KeyQ = 113 KeyR = 114 KeyS = 115 KeyT = 116 KeyU = 117 KeyV = 118 KeyW = 119 KeyX = 120 KeyY = 121 KeyZ = 122 F1 = 129 F2 = 130 F3 = 131 F4 = 132 F5 = 133 F6 = 134 F7 = 135 F8 = 136 F9 = 137 F10 = 138 F11 = 139 F12 = 140 CapsLock = 150 NumLock = 151 ScrollLock = 152 PrintScreen = 153 Pause = 154 LeftShift = 155 RightShift = 156 LeftControl = 157 RightControl = 158 LeftAlt = 159 RightAlt = 160 LeftGui = 161 RightGui = 162 Right = 166 Left = 167 Up = 168 Down = 169 KeyPadDivide = 170 KeyPadMultiply = 171 KeyPadSubtract = 172 KeyPadAdd = 173 KeyPadEnter = 174 KeyPadDecimal = 175 KeyPadEquals = 176 KeyPad0 = 177 KeyPad1 = 178 KeyPad2 = 179 KeyPad3 = 180 KeyPad4 = 181 KeyPad5 = 182 KeyPad6 = 183 KeyPad7 = 184 KeyPad8 = 185 KeyPad9 = 186 KeyDelete = 190 KeyHome = 191 KeyInsert = 192 KeyEnd = 193 KeyPageUp = 194 KeyPageDown = 195 MouseXAxis = 300 MouseYAxis = 301 MouseWheelVertical = 302 MouseWheelHorizontal = 303 MouseLButton = 304 MouseRButton = 305 MouseMButton = 306 // standard derived keys start here DerivedKeysRangeStart = 1000 EitherShift = 1000 + iota EitherControl EitherAlt EitherGui ShiftTab DeleteOrBackspace DerivedKeysRangeEnd // non-inclusive! )
Variables ¶
var ( AnyAnyKey = KeyId{Index: AnyKey, Device: DeviceId{Type: DeviceTypeAny, Index: DeviceIndexAny}} AnySpace = KeyId{Index: Space, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyBackspace = KeyId{Index: Backspace, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyTab = KeyId{Index: Tab, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyReturn = KeyId{Index: Return, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyEscape = KeyId{Index: Escape, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyA = KeyId{Index: KeyA, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyB = KeyId{Index: KeyB, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyC = KeyId{Index: KeyC, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyD = KeyId{Index: KeyD, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyE = KeyId{Index: KeyE, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyF = KeyId{Index: KeyF, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyG = KeyId{Index: KeyG, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyH = KeyId{Index: KeyH, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyI = KeyId{Index: KeyI, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyJ = KeyId{Index: KeyJ, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyK = KeyId{Index: KeyK, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyL = KeyId{Index: KeyL, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyM = KeyId{Index: KeyM, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyN = KeyId{Index: KeyN, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyO = KeyId{Index: KeyO, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyP = KeyId{Index: KeyP, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyQ = KeyId{Index: KeyQ, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyR = KeyId{Index: KeyR, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyS = KeyId{Index: KeyS, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyT = KeyId{Index: KeyT, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyU = KeyId{Index: KeyU, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyV = KeyId{Index: KeyV, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyW = KeyId{Index: KeyW, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyX = KeyId{Index: KeyX, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyY = KeyId{Index: KeyY, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyZ = KeyId{Index: KeyZ, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyF1 = KeyId{Index: F1, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyF2 = KeyId{Index: F2, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyF3 = KeyId{Index: F3, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyF4 = KeyId{Index: F4, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyF5 = KeyId{Index: F5, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyF6 = KeyId{Index: F6, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyF7 = KeyId{Index: F7, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyF8 = KeyId{Index: F8, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyF9 = KeyId{Index: F9, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyF10 = KeyId{Index: F10, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyF11 = KeyId{Index: F11, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyF12 = KeyId{Index: F12, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyCapsLock = KeyId{Index: CapsLock, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyNumLock = KeyId{Index: NumLock, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyScrollLock = KeyId{Index: ScrollLock, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyPrintScreen = KeyId{Index: PrintScreen, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyPause = KeyId{Index: Pause, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyLeftShift = KeyId{Index: LeftShift, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyRightShift = KeyId{Index: RightShift, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyLeftControl = KeyId{Index: LeftControl, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyRightControl = KeyId{Index: RightControl, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyLeftAlt = KeyId{Index: LeftAlt, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyRightAlt = KeyId{Index: RightAlt, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyLeftGui = KeyId{Index: LeftGui, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyRightGui = KeyId{Index: RightGui, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyRight = KeyId{Index: Right, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyLeft = KeyId{Index: Left, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyUp = KeyId{Index: Up, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyDown = KeyId{Index: Down, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyPadDivide = KeyId{Index: KeyPadDivide, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyPadMultiply = KeyId{Index: KeyPadMultiply, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyPadSubtract = KeyId{Index: KeyPadSubtract, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyPadAdd = KeyId{Index: KeyPadAdd, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyPadEnter = KeyId{Index: KeyPadEnter, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyPadDecimal = KeyId{Index: KeyPadDecimal, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyPadEquals = KeyId{Index: KeyPadEquals, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyPad0 = KeyId{Index: KeyPad0, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyPad1 = KeyId{Index: KeyPad1, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyPad2 = KeyId{Index: KeyPad2, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyPad3 = KeyId{Index: KeyPad3, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyPad4 = KeyId{Index: KeyPad4, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyPad5 = KeyId{Index: KeyPad5, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyPad6 = KeyId{Index: KeyPad6, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyPad7 = KeyId{Index: KeyPad7, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyPad8 = KeyId{Index: KeyPad8, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyPad9 = KeyId{Index: KeyPad9, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyDelete = KeyId{Index: KeyDelete, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyHome = KeyId{Index: KeyHome, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyInsert = KeyId{Index: KeyInsert, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyEnd = KeyId{Index: KeyEnd, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyPageUp = KeyId{Index: KeyPageUp, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyKeyPageDown = KeyId{Index: KeyPageDown, Device: DeviceId{Type: DeviceTypeKeyboard, Index: DeviceIndexAny}} AnyMouseXAxis = KeyId{Index: MouseXAxis, Device: DeviceId{Type: DeviceTypeMouse, Index: DeviceIndexAny}} AnyMouseYAxis = KeyId{Index: MouseYAxis, Device: DeviceId{Type: DeviceTypeMouse, Index: DeviceIndexAny}} AnyMouseWheelVertical = KeyId{Index: MouseWheelVertical, Device: DeviceId{Type: DeviceTypeMouse, Index: DeviceIndexAny}} AnyMouseWheelHorizontal = KeyId{Index: MouseWheelHorizontal, Device: DeviceId{Type: DeviceTypeMouse, Index: DeviceIndexAny}} AnyMouseLButton = KeyId{Index: MouseLButton, Device: DeviceId{Type: DeviceTypeMouse, Index: DeviceIndexAny}} AnyMouseRButton = KeyId{Index: MouseRButton, Device: DeviceId{Type: DeviceTypeMouse, Index: DeviceIndexAny}} AnyMouseMButton = KeyId{Index: MouseMButton, Device: DeviceId{Type: DeviceTypeMouse, Index: DeviceIndexAny}} )
Functions ¶
This section is empty.
Types ¶
type Binding ¶
A Binding, b, is considered down if b.PrimaryKey is down and all of b.Modifiers[i].IsDown() matches b.Down[i]. Yes, KeyIds don't have an IsDown(), we're really talking about the Key instance identified by the KeyId.
func (*Binding) CurPressAmt ¶
type DeviceId ¶
type DeviceId struct {
Type DeviceType
Index DeviceIndex
}
type DeviceIndex ¶
type DeviceIndex int
const (
DeviceIndexAny DeviceIndex = -1
)
func (DeviceIndex) Contains ¶
func (di DeviceIndex) Contains(other DeviceIndex) bool
type DeviceType ¶
type DeviceType int
const ( DeviceTypeAny DeviceType = iota DeviceTypeKeyboard DeviceTypeMouse DeviceTypeController DeviceTypeDerived DeviceTypeMax )
func (DeviceType) Contains ¶
func (dt DeviceType) Contains(other DeviceType) bool
func (DeviceType) String ¶
func (dt DeviceType) String() string
type Event ¶
type Event struct {
Key Key
Type aggregator.EventType
}
type EventDispatcher ¶
type EventDispatcher interface {
RegisterEventListener(Listener)
}
type EventGroup ¶
type EventGroup struct {
Events []Event
TimestampMs int64
// contains filtered or unexported fields
}
An EventGroup is a series of events that were all created by a single OsEvent.
func (*EventGroup) FindEvent ¶
func (eg *EventGroup) FindEvent(id KeyId) (Event, bool)
Returns a bool indicating whether an event corresponding to the given KeyId is present in the EventGroup, and if so the Event returned is a copy of that event.
func (*EventGroup) GetMousePosition ¶
func (eg *EventGroup) GetMousePosition() (int, int)
func (*EventGroup) HasMousePosition ¶
func (eg *EventGroup) HasMousePosition() bool
func (*EventGroup) IsMouseMove ¶
func (eg *EventGroup) IsMouseMove() bool
func (*EventGroup) IsPressed ¶
func (eg *EventGroup) IsPressed(id KeyId) bool
Returns true if the given KeyId is considered 'Pressed' within this event group.
func (*EventGroup) IsReleased ¶
func (eg *EventGroup) IsReleased(id KeyId) bool
Returns true if the given KeyId is considered 'Released' within this event group.
func (*EventGroup) PrimaryEvent ¶
func (eg *EventGroup) PrimaryEvent() Event
Returns the root-cause event of the EventGroup. Useful for classifying the group as a whole.
func (*EventGroup) SetMousePosition ¶
func (eg *EventGroup) SetMousePosition(x, y int)
func (EventGroup) String ¶
func (eg EventGroup) String() string
type Input ¶
type Input struct {
// contains filtered or unexported fields
}
Everything 'global' is put inside a struct so that tests can be run without stepping on each other.
func In ¶
func In() *Input
TODO: You messed up, the name of this function should be Input, and it should return an interface or something that is not called Input
func MakeLogged ¶
Creates a new input object, mostly for testing. Most users will just query gin.Input, which is created during initialization
func (*Input) BindDerivedKey ¶
func (*Input) GetKeyById ¶
func (*Input) GetKeyByParts ¶
func (input *Input) GetKeyByParts(key_index KeyIndex, device_type DeviceType, device_index DeviceIndex) Key
func (*Input) MakeBinding ¶
func (*Input) RegisterEventListener ¶
The Input object can have multiple Listener instances registered with it. Each Listener will receive event groups as they are processed. Each Listener will also get a .Think() call once per frame after all input events for the frame have been processed.
type Key ¶
type Key interface {
// Human readable name
String() string
// Raw name, usable for lookup by GetKeyByName()
Name() string
// Unique Id
Id() KeyId
// Sets the instantaneous press amount for this key at a specific time and
// returns the event generated, if any.
KeySetPressAmt(amt float64, ms int64, cause Event) Event
// A Key may return true, amt from KeyThink() to indicate that a fake event
// should be generated to set its press amount to amt.
KeyThink(ms int64) (bool, float64)
aggregator.SubAggregator
}
type KeyId ¶
func (KeyId) Contains ¶
KeyIds support a quasi-wildcard form where an event for a single ID can 'cascade' over a set of other keys. Contains returns true iff the set of Keys covered by the 'cascade' includes the given KeyId.
func (KeyId) MustValidate ¶
func (kid KeyId) MustValidate()
type Listener ¶
type Listener interface {
HandleEventGroup(EventGroup)
Think(int64)
}
During HandleEventGroup a Listener can query keys as to their current state (i.e. with Cur*() methods) and these will accurately report their state.
Frame*() methods on keys will report state from last frame.
Listener.Think() will be called after all the events for a frame have been processed.
type MousePosition ¶
type MousePosition struct {
X, Y int
}