mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-18 03:24:00 +00:00
usbhid: add support for mouse buttons (#2900)
* usbhid: add support for mouse buttons
This commit is contained in:
@@ -6,8 +6,17 @@ import (
|
|||||||
|
|
||||||
var Mouse *mouse
|
var Mouse *mouse
|
||||||
|
|
||||||
|
type Button byte
|
||||||
|
|
||||||
|
const (
|
||||||
|
Left Button = 1 << iota
|
||||||
|
Right
|
||||||
|
Middle
|
||||||
|
)
|
||||||
|
|
||||||
type mouse struct {
|
type mouse struct {
|
||||||
buf *hid.RingBuffer
|
buf *hid.RingBuffer
|
||||||
|
button Button
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -57,11 +66,33 @@ func (m *mouse) Move(vx, vy int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m.buf.Put([]byte{
|
m.buf.Put([]byte{
|
||||||
0x01, 0x00, byte(vx), byte(vy), 0x00,
|
0x01, byte(m.button), byte(vx), byte(vy), 0x00,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// WHEEL controls the mouse wheel.
|
// Cilck clicks the mouse button.
|
||||||
|
func (m *mouse) Click(btn Button) {
|
||||||
|
m.Press(btn)
|
||||||
|
m.Release(btn)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Press presses the given mouse buttons.
|
||||||
|
func (m *mouse) Press(btn Button) {
|
||||||
|
m.button |= btn
|
||||||
|
m.buf.Put([]byte{
|
||||||
|
0x01, byte(m.button), 0x00, 0x00, 0x00,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release releases the given mouse buttons.
|
||||||
|
func (m *mouse) Release(btn Button) {
|
||||||
|
m.button &= ^btn
|
||||||
|
m.buf.Put([]byte{
|
||||||
|
0x01, byte(m.button), 0x00, 0x00, 0x00,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wheel controls the mouse wheel.
|
||||||
func (m *mouse) Wheel(v int) {
|
func (m *mouse) Wheel(v int) {
|
||||||
if v == 0 {
|
if v == 0 {
|
||||||
return
|
return
|
||||||
@@ -75,7 +106,7 @@ func (m *mouse) Wheel(v int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m.buf.Put([]byte{
|
m.buf.Put([]byte{
|
||||||
0x01, 0x00, 0x00, 0x00, byte(v),
|
0x01, byte(m.button), 0x00, 0x00, byte(v),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user