-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathevent.go
117 lines (101 loc) · 3.79 KB
/
event.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package input
// SimulatedKeyEvent represents a virtual input that can be send down the stream.
//
// The data carried by this event will be used to construct an EventInfo object.
//
// Experimental: this is a part of virtual input API, which is not stable yet.
type SimulatedKeyEvent struct {
Key Key
Pos Vec
}
// SimulatedAction represents an artificially triggered action.
//
// It shares many properties with SimulatedKeyEvent, but
// the event consumers will have no way of knowing which input
// device was used to emit this event, because SimulatedAction
// has no device associated with it.
//
// As a consequence, all event info methods like IsGamepadeEvent() will report false.
// It's possible to trigger an action that has no keys associated with it.
// All actions triggered using this method will be only visible to the handler
// of the same player ID (like gamepad button events).
//
// Experimental: this is a part of virtual input API, which is not stable yet.
type SimulatedAction struct {
Action Action
Pos Vec
StartPos Vec
}
// EventInfo holds extra information about the input device event.
//
// Pos carries the event location, if available.
// Pos is a click location for mouse events.
// Pos is a tap location for screen touch events.
// Use HasPos() predicate to know whether there is a pos associated
// with the event to distinguish between (0, 0) pos and lack of pos info.
//
// StartPos is only set for a few events where it makes sense.
// A drag event, for instance, will store the "dragging from" location there.
//
// Duration carries the key press duration if available.
// Duration specifies how long the key has been pressed in ticks same as inpututil.KeyPressDuration.
// Duration for key press with modifiers it will return the lowest duration of all key presses.
// Use HasDuration() predicate to know whether there is a duration associated
// with the event to distinguish between 0 duration and lack of duration info.
type EventInfo struct {
kind keyKind
hasPos bool
hasDuration bool
Duration int
Pos Vec
StartPos Vec
}
// HasPos reports whether this event has a position associated with it.
// Use Pos field to get the pos value.
func (e EventInfo) HasPos() bool { return e.hasPos }
// HasDuration reports whether this event has a press duration associated with it.
// Use Duration field to get the press duration value.
func (e EventInfo) HasDuration() bool { return e.hasDuration }
// IsTouchEvent reports whether this event was triggered by a screen touch device.
//
// Deprecated: Use Source().IsTouch() instead.
func (e EventInfo) IsTouchEvent() bool {
return e.Source().IsTouch()
}
// IsKeyboardEvent reports whether this event was triggered by a keyboard device.
//
// Deprecated: Use Source().IsKeyboard() instead.
func (e EventInfo) IsKeyboardEvent() bool {
return e.Source().IsKeyboard()
}
// IsMouseEvent reports whether this event was triggered by a mouse device.
//
// Deprecated: Use Source().IsMouse() instead.
func (e EventInfo) IsMouseEvent() bool {
return e.Source().IsMouse()
}
// IsGamepadEvent reports whether this event was triggered by a gamepad device.
//
// Deprecated: Use Source().IsGamepad() instead.
func (e EventInfo) IsGamepadEvent() bool {
return e.Source().IsGamepad()
}
// Source returns the set of devices that were used to trigger the event.
//
// Usually, it returns a single device mask, but sometimes an action
// can be triggered by several devices.
// For example, a ctrl+click key would involve both keyboard and mouse devices,
// resulting in a KeyboardDevice|KeyboardMouse value.
//
// A simulated event would have a zero mask returned, meaning
// no real device was involved.
func (e EventInfo) Source() DeviceKind {
return e.kind.device()
}
type simulatedEvent struct {
code int
keyKind keyKind
playerID uint8
pos Vec
startPos Vec
}