@@ -6,8 +6,17 @@ import (
6
6
7
7
var Mouse * mouse
8
8
9
+ type Button byte
10
+
11
+ const (
12
+ Left Button = 1 << iota
13
+ Right
14
+ Middle
15
+ )
16
+
9
17
type mouse struct {
10
- buf * hid.RingBuffer
18
+ buf * hid.RingBuffer
19
+ button Button
11
20
}
12
21
13
22
func init () {
@@ -57,11 +66,33 @@ func (m *mouse) Move(vx, vy int) {
57
66
}
58
67
59
68
m .buf .Put ([]byte {
60
- 0x01 , 0x00 , byte (vx ), byte (vy ), 0x00 ,
69
+ 0x01 , byte (m .button ), byte (vx ), byte (vy ), 0x00 ,
70
+ })
71
+ }
72
+
73
+ // Cilck clicks the mouse button.
74
+ func (m * mouse ) Click (btn Button ) {
75
+ m .Press (btn )
76
+ m .Release (btn )
77
+ }
78
+
79
+ // Press presses the given mouse buttons.
80
+ func (m * mouse ) Press (btn Button ) {
81
+ m .button |= btn
82
+ m .buf .Put ([]byte {
83
+ 0x01 , byte (m .button ), 0x00 , 0x00 , 0x00 ,
84
+ })
85
+ }
86
+
87
+ // Release releases the given mouse buttons.
88
+ func (m * mouse ) Release (btn Button ) {
89
+ m .button &= ^ btn
90
+ m .buf .Put ([]byte {
91
+ 0x01 , byte (m .button ), 0x00 , 0x00 , 0x00 ,
61
92
})
62
93
}
63
94
64
- // WHEEL controls the mouse wheel.
95
+ // Wheel controls the mouse wheel.
65
96
func (m * mouse ) Wheel (v int ) {
66
97
if v == 0 {
67
98
return
@@ -75,7 +106,7 @@ func (m *mouse) Wheel(v int) {
75
106
}
76
107
77
108
m .buf .Put ([]byte {
78
- 0x01 , 0x00 , 0x00 , 0x00 , byte (v ),
109
+ 0x01 , byte ( m . button ) , 0x00 , 0x00 , byte (v ),
79
110
})
80
111
}
81
112
0 commit comments