Skip to content

Commit ed15adc

Browse files
committed
Mouse movement works, but has issues with multiple monitors in Host
device
1 parent 7f7036a commit ed15adc

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

frontend/src/lib/mouse/mouse_hook.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ export function handleMove(callback: mouseHandler) {
5151
const yAxis = event.pageY;
5252
console.log(`Move x:${xAxis}, y:${yAxis}`);
5353

54-
const buf = new ArrayBuffer(1 + (8 * 8) * 2)
54+
const buf = new ArrayBuffer(1 + (2 * 2))
5555
const view = new DataView(buf);
5656

5757
view.setUint8(0, MouseType.Move)
58-
view.setBigUint64(1, BigInt(xAxis))
59-
view.setBigUint64(2 + 8 * 8, BigInt(yAxis))
58+
view.setUint16(1, xAxis)
59+
view.setUint16(1 + 2, yAxis)
6060

6161
return callback(buf);
6262
};

src/devices/mouse/handler.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ import (
1212

1313
var MouseEnabled = new(devices.DeviceEnabled).Disable()
1414

15-
func HandleMouse(d *webrtc.DataChannel) error {
15+
func HandleMouse(d *webrtc.DataChannel) {
1616

1717
if d.Label() != "mouse" {
18-
return nil
18+
return
1919
}
2020

2121
d.OnOpen(func() {
22+
23+
robotgo.MouseSleep = 100
24+
2225
log.Println("mouse data channel is open")
2326
})
2427

@@ -61,12 +64,13 @@ func HandleMouse(d *webrtc.DataChannel) error {
6164

6265
var state string
6366

64-
if btnState == mouseDown {
67+
switch btnState {
68+
case mouseDown:
6569
state = "down"
66-
} else if btnState == mouseUp {
70+
case mouseUp:
6771
state = "up"
6872
}
69-
73+
7074
switch clickBtn {
7175
case mouseLeft:
7276
robotgo.Toggle("left", state)
@@ -78,26 +82,29 @@ func HandleMouse(d *webrtc.DataChannel) error {
7882

7983
} else if msgType == typeMsgMove { // Handle move event
8084

81-
// TODO: do some logging to check the values
82-
83-
x, err := binary.ReadUvarint(msgBuf)
85+
x := make([]byte, 2)
86+
_, err := msgBuf.Read(x)
8487

8588
if err != nil {
8689
return
8790
}
88-
89-
y, err := binary.ReadUvarint(msgBuf)
91+
92+
y := make([]byte, 2)
93+
_, err = msgBuf.Read(y)
9094

9195
if err != nil {
9296
return
9397
}
9498

95-
robotgo.Move(int(x), int(y))
99+
xNum := binary.BigEndian.Uint16(x)
100+
yNum := binary.BigEndian.Uint16(y)
101+
102+
// log.Printf("Mouse x: %d, y:%d\n", int(xNum), int(yNum))
103+
104+
robotgo.Move(int(xNum), int(yNum))
96105

97106
}
98107

99108
})
100109

101-
return nil
102-
103110
}

0 commit comments

Comments
 (0)