Advertisement
Josiahiscool73

Simulate mouse movements in xcloud(no controller emulation)

May 10th, 2025
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. function simulateMouseMovementOnXCloud() {
  2. // Define start and end coordinates in viewport pixels
  3. const startX = window.innerWidth / 4;
  4. const startY = window.innerHeight / 4;
  5. const endX = window.innerWidth / 2;
  6. const endY = window.innerHeight / 2;
  7.  
  8. console.log(`[XCloud Sim] Simulating mouse movement from viewport coordinates (${Math.round(startX)}, ${Math.round(startY)}) to (${Math.round(endX)}, ${Math.round(endY)})`);
  9.  
  10. // 1. Simulate a pointermove to the starting position.
  11. // This helps establish an initial point, especially if absolute mouse mode is active.
  12. // The MouseManager's internal `lastAbsoluteX` and `lastAbsoluteY` might be updated.
  13. const initialMoveEvent = new PointerEvent('pointermove', {
  14. bubbles: true, // Should bubble up the DOM
  15. cancelable: true, // Can be canceled
  16. view: window, // The window context
  17. clientX: startX,
  18. clientY: startY,
  19. movementX: 0, // No movement relative to a "previous" point for this first event
  20. movementY: 0,
  21. pointerType: 'mouse', // Critical, as MouseManager checks e.pointerType === 'mouse'
  22. buttons: 0 // No mouse buttons pressed
  23. });
  24. window.dispatchEvent(initialMoveEvent);
  25. console.log("[XCloud Sim] Dispatched initial 'pointermove' to start position.");
  26.  
  27. // 2. Simulate a pointermove to the ending position.
  28. // A small delay can sometimes help ensure the browser/page processes events sequentially.
  29. setTimeout(() => {
  30. const moveEvent = new PointerEvent('pointermove', {
  31. bubbles: true,
  32. cancelable: true,
  33. view: window,
  34. clientX: endX,
  35. clientY: endY,
  36. movementX: endX - startX, // Relative movement from the startX
  37. movementY: endY - startY, // Relative movement from the startY
  38. pointerType: 'mouse',
  39. buttons: 0 // No mouse buttons pressed
  40. });
  41. window.dispatchEvent(moveEvent);
  42. console.log("[XCloud Sim] Dispatched 'pointermove' to end position.");
  43. console.log("[XCloud Sim] Mouse movement simulation attempt complete.");
  44. }, 100); // 100ms delay before the main move
  45. }
  46.  
  47. console.log("[XCloud Sim] Script loaded. Waiting 5 seconds to simulate mouse movement...");
  48. setTimeout(simulateMouseMovementOnXCloud, 5000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement