da03 commited on
Commit
9d14994
·
1 Parent(s): 9147f8e
Files changed (1) hide show
  1. static/index.html +6 -27
static/index.html CHANGED
@@ -322,9 +322,6 @@
322
  let timeoutCountdown = 10;
323
  let timeoutWarningActive = false;
324
 
325
- // Track currently pressed keys
326
- const pressedKeys = new Set();
327
-
328
  function startAutoInput() {
329
  if (autoInputInterval) {
330
  clearInterval(autoInputInterval);
@@ -479,17 +476,17 @@
479
  stopTimeoutCountdown();
480
  }
481
 
482
- function sendInputState(x, y, isLeftClick = false, isRightClick = false) {
483
  const currentTime = Date.now();
484
- if (isConnected && socket.readyState === WebSocket.OPEN && (isLeftClick || isRightClick || !lastSentPosition || currentTime - lastSentTime >= SEND_INTERVAL)) {
485
  try {
486
  socket.send(JSON.stringify({
487
  "x": x,
488
  "y": y,
489
  "is_left_click": isLeftClick,
490
  "is_right_click": isRightClick,
491
- "keys_down": Array.from(pressedKeys),
492
- "keys_up": [],
493
  }));
494
  lastSentPosition = { x, y };
495
  lastSentTime = currentTime;
@@ -580,42 +577,24 @@
580
  document.addEventListener("keydown", function (event) {
581
  if (!isConnected || isProcessing) return;
582
 
583
- // Add the key to our set of pressed keys
584
- pressedKeys.add(event.key);
585
-
586
  // Get the current mouse position
587
  let rect = canvas.getBoundingClientRect();
588
  let x = lastSentPosition ? lastSentPosition.x : canvas.width / 2;
589
  let y = lastSentPosition ? lastSentPosition.y : canvas.height / 2;
590
 
591
- sendInputState(x, y);
592
  });
593
 
594
  document.addEventListener("keyup", function (event) {
595
  if (!isConnected || socket.readyState !== WebSocket.OPEN) return;
596
 
597
- // Remove the key from our set of pressed keys
598
- pressedKeys.delete(event.key);
599
-
600
  // Get the current mouse position
601
  let rect = canvas.getBoundingClientRect();
602
  let x = lastSentPosition ? lastSentPosition.x : canvas.width / 2;
603
  let y = lastSentPosition ? lastSentPosition.y : canvas.height / 2;
604
 
605
  // For key up events, we send the key in the keys_up array
606
- try {
607
- socket.send(JSON.stringify({
608
- "x": x,
609
- "y": y,
610
- "is_left_click": false,
611
- "is_right_click": false,
612
- "keys_down": Array.from(pressedKeys),
613
- "keys_up": [event.key],
614
- }));
615
- updateLastUserInputTime(); // Update for auto-input mechanism
616
- } catch (error) {
617
- console.error("Error sending key up event:", error);
618
- }
619
  });
620
 
621
  // Graceful disconnection
 
322
  let timeoutCountdown = 10;
323
  let timeoutWarningActive = false;
324
 
 
 
 
325
  function startAutoInput() {
326
  if (autoInputInterval) {
327
  clearInterval(autoInputInterval);
 
476
  stopTimeoutCountdown();
477
  }
478
 
479
+ function sendInputState(x, y, isLeftClick = false, isRightClick = false, keysDownArr = [], keysUpArr = []) {
480
  const currentTime = Date.now();
481
+ if (isConnected && socket.readyState === WebSocket.OPEN && (isLeftClick || isRightClick || keysDownArr.length > 0 || keysUpArr.length > 0 || !lastSentPosition || currentTime - lastSentTime >= SEND_INTERVAL)) {
482
  try {
483
  socket.send(JSON.stringify({
484
  "x": x,
485
  "y": y,
486
  "is_left_click": isLeftClick,
487
  "is_right_click": isRightClick,
488
+ "keys_down": keysDownArr,
489
+ "keys_up": keysUpArr,
490
  }));
491
  lastSentPosition = { x, y };
492
  lastSentTime = currentTime;
 
577
  document.addEventListener("keydown", function (event) {
578
  if (!isConnected || isProcessing) return;
579
 
 
 
 
580
  // Get the current mouse position
581
  let rect = canvas.getBoundingClientRect();
582
  let x = lastSentPosition ? lastSentPosition.x : canvas.width / 2;
583
  let y = lastSentPosition ? lastSentPosition.y : canvas.height / 2;
584
 
585
+ sendInputState(x, y, false, false, [event.key], []);
586
  });
587
 
588
  document.addEventListener("keyup", function (event) {
589
  if (!isConnected || socket.readyState !== WebSocket.OPEN) return;
590
 
 
 
 
591
  // Get the current mouse position
592
  let rect = canvas.getBoundingClientRect();
593
  let x = lastSentPosition ? lastSentPosition.x : canvas.width / 2;
594
  let y = lastSentPosition ? lastSentPosition.y : canvas.height / 2;
595
 
596
  // For key up events, we send the key in the keys_up array
597
+ sendInputState(x, y, false, false, [], [event.key]);
 
 
 
 
 
 
 
 
 
 
 
 
598
  });
599
 
600
  // Graceful disconnection