|
@@ -36,16 +36,22 @@
|
|
let socketURL = `${protocol}://${window.location.hostname}:${port}/hid`;
|
|
let socketURL = `${protocol}://${window.location.hostname}:${port}/hid`;
|
|
let mouseMoveAbsolte = true; // Set to true for absolute mouse coordinates, false for relativeZ
|
|
let mouseMoveAbsolte = true; // Set to true for absolute mouse coordinates, false for relativeZ
|
|
let mouseIsOutside = false;
|
|
let mouseIsOutside = false;
|
|
|
|
+ let mouseButtonState = [0, 0, 0]; // Array to track mouse button states, left, middle, right
|
|
|
|
|
|
/* Mouse events */
|
|
/* Mouse events */
|
|
function handleMouseMove(event) {
|
|
function handleMouseMove(event) {
|
|
|
|
+ const mouseButtonBits = mouseButtonState.reduce((acc, state, index) => {
|
|
|
|
+ return acc | (state << index);
|
|
|
|
+ }, 0);
|
|
const hidCommand = {
|
|
const hidCommand = {
|
|
event: 2,
|
|
event: 2,
|
|
mouse_x: event.clientX,
|
|
mouse_x: event.clientX,
|
|
- mouse_y: event.clientY
|
|
|
|
|
|
+ mouse_y: event.clientY,
|
|
|
|
+ mouse_move_button_state: mouseButtonBits // Combine mouse button states into a single bitmask
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
const rect = event.target.getBoundingClientRect();
|
|
const rect = event.target.getBoundingClientRect();
|
|
const relativeX = event.clientX - rect.left;
|
|
const relativeX = event.clientX - rect.left;
|
|
const relativeY = event.clientY - rect.top;
|
|
const relativeY = event.clientY - rect.top;
|
|
@@ -91,6 +97,12 @@
|
|
mouse_button: buttonMap[event.button] || 0
|
|
mouse_button: buttonMap[event.button] || 0
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ // Update mouse button state
|
|
|
|
+ if (event.button >= 0 && event.button < mouseButtonState.length) {
|
|
|
|
+ mouseButtonState[event.button] = 1; // Set button state to pressed
|
|
|
|
+ }
|
|
|
|
+ // Log the mouse button state
|
|
|
|
+
|
|
console.log(`Mouse down: ${hidCommand.mouse_button}`);
|
|
console.log(`Mouse down: ${hidCommand.mouse_button}`);
|
|
|
|
|
|
if (socket && socket.readyState === WebSocket.OPEN) {
|
|
if (socket && socket.readyState === WebSocket.OPEN) {
|
|
@@ -112,12 +124,17 @@
|
|
1: 3,
|
|
1: 3,
|
|
2: 2
|
|
2: 2
|
|
}; //Map javascript mouse buttons to HID buttons
|
|
}; //Map javascript mouse buttons to HID buttons
|
|
-
|
|
|
|
|
|
+
|
|
const hidCommand = {
|
|
const hidCommand = {
|
|
event: 4,
|
|
event: 4,
|
|
mouse_button: buttonMap[event.button] || 0
|
|
mouse_button: buttonMap[event.button] || 0
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ // Update mouse button state
|
|
|
|
+ if (event.button >= 0 && event.button < mouseButtonState.length) {
|
|
|
|
+ mouseButtonState[event.button] = 0; // Set button state to released
|
|
|
|
+ }
|
|
|
|
+
|
|
console.log(`Mouse release: ${hidCommand.mouse_button}`);
|
|
console.log(`Mouse release: ${hidCommand.mouse_button}`);
|
|
|
|
|
|
if (socket && socket.readyState === WebSocket.OPEN) {
|
|
if (socket && socket.readyState === WebSocket.OPEN) {
|