-
Notifications
You must be signed in to change notification settings - Fork 2
/
event.go
150 lines (129 loc) · 4.37 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package input
import (
"encoding/binary"
"io"
"syscall"
"time"
)
// We need the input_event struct from https://android.googlesource.com/platform/system/core/+/froyo-release/toolbox/sendevent.c
/*
struct input_event {
struct timeval time;
__u16 type;
__u16 code;
__s32 value;
};
*/
/*
$ getevent
add device 7: /dev/input/event1
name: "synaptics_dsx"
events:
KEY (0001): KEY_WAKEUP BTN_TOOL_FINGER BTN_TOUCH
ABS (0003): ABS_X : value 0, min 0, max 1079, fuzz 0, flat 0, resolution 0
ABS_Y : value 0, min 0, max 2159, fuzz 0, flat 0, resolution 0
ABS_MT_SLOT : value 0, min 0, max 9, fuzz 0, flat 0, resolution 0
ABS_MT_TOUCH_MAJOR : value 0, min 0, max 255, fuzz 0, flat 0, resolution 0
ABS_MT_TOUCH_MINOR : value 0, min 0, max 255, fuzz 0, flat 0, resolution 0
ABS_MT_POSITION_X : value 0, min 0, max 1079, fuzz 0, flat 0, resolution 0
ABS_MT_POSITION_Y : value 0, min 0, max 2159, fuzz 0, flat 0, resolution 0
ABS_MT_TRACKING_ID : value 0, min 0, max 65535, fuzz 0, flat 0, resolution 0
input props:
INPUT_PROP_DIRECT
add device 7: /dev/input/event1
name: "synaptics_dsx"
events:
KEY (0001): 008f 0145 014a
ABS (0003): 0000 : value 0, min 0, max 1079, fuzz 0, flat 0, resolution 0
0001 : value 0, min 0, max 2159, fuzz 0, flat 0, resolution 0
002f : value 0, min 0, max 9, fuzz 0, flat 0, resolution 0
0030 : value 0, min 0, max 255, fuzz 0, flat 0, resolution 0
0031 : value 0, min 0, max 255, fuzz 0, flat 0, resolution 0
0035 : value 0, min 0, max 1079, fuzz 0, flat 0, resolution 0
0036 : value 0, min 0, max 2159, fuzz 0, flat 0, resolution 0
0039 : value 0, min 0, max 65535, fuzz 0, flat 0, resolution 0
input props:
INPUT_PROP_DIRECT
*/
/*
Putting finger in top left corner:
$ getevent
/dev/input/event1: 0003 0039 000000e7
/dev/input/event1: 0001 014a 00000001
/dev/input/event1: 0001 0145 00000001
/dev/input/event1: 0003 0035 00000078
/dev/input/event1: 0003 0036 000000e2
/dev/input/event1: 0003 0030 00000006
/dev/input/event1: 0000 0000 00000000
/dev/input/event1: 0003 0039 ffffffff
/dev/input/event1: 0001 014a 00000000
/dev/input/event1: 0001 0145 00000000
/dev/input/event1: 0000 0000 00000000
Same thing:
$ getevent
/dev/input/event1: EV_ABS ABS_MT_TRACKING_ID 000000e8
/dev/input/event1: EV_KEY BTN_TOUCH DOWN
/dev/input/event1: EV_KEY BTN_TOOL_FINGER DOWN
/dev/input/event1: EV_ABS ABS_MT_POSITION_X 0000007a
/dev/input/event1: EV_ABS ABS_MT_POSITION_Y 000000a3
/dev/input/event1: EV_ABS ABS_MT_TOUCH_MAJOR 00000005
/dev/input/event1: EV_SYN SYN_REPORT 00000000
/dev/input/event1: EV_ABS ABS_MT_TOUCH_MAJOR 00000006
/dev/input/event1: EV_SYN SYN_REPORT 00000000
/dev/input/event1: EV_ABS ABS_MT_TRACKING_ID ffffffff
/dev/input/event1: EV_KEY BTN_TOUCH UP
/dev/input/event1: EV_KEY BTN_TOOL_FINGER UP
/dev/input/event1: EV_SYN SYN_REPORT 00000000
*/
// that's it. That's the struct
type InputEvent struct {
Time syscall.Timeval
Type EventType
Code EventCode
Value uint32
}
// Here are some constants I infered from the output above
type EventType uint16
const (
EV_ABS EventType = 0x0003
EV_KEY EventType = 0x0001
EV_SYN EventType = 0x0000
)
type EventCode uint16
const (
ABS_MT_TRACKING_ID EventCode = 0x0039
BTN_TOUCH EventCode = 0x014a
BTN_TOOL_FINGER EventCode = 0x0145
ABS_MT_POSITION_X EventCode = 0x0035
ABS_MT_POSITION_Y EventCode = 0x0036
ABS_MT_TOUCH_MAJOR EventCode = 0x0030
SYN_REPORT EventCode = 0x0000
)
const (
DOWN = 0x00000001
UP = 0x00000000
)
const (
PAUSE EventType = 0x3210
)
var (
eventSynReport = InputEvent{
Type: EV_SYN,
Code: SYN_REPORT,
Value: 0x00000000,
}
)
func runEvents(output io.Writer, events []InputEvent) (err error) {
for _, ievent := range events {
// The PAUSE event doesn't exist, I just chose the number
if ievent.Type == PAUSE {
time.Sleep(time.Duration(ievent.Value) * time.Millisecond)
continue
}
err = binary.Write(output, binary.LittleEndian, ievent)
if err != nil {
return err
}
}
return nil
}