You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hammerspoon cannot simulate mouse movement or clicks in GeForceNow (or maybe other apps, and I don't know why, because of app implementation or full screen mode), where Apple Script works fine.
Why? Should I enable some special mode?.. Thank you for any feedback.
And thank you for work on this app! :)
Description
I'm trying to make some automation in a GeForceNow.
The application does not respond to mouse movements nor mouse clicks.
I've been testing this script to move a mouse through a menu in a game (feel free to add clicks if needed).
Menu items should react with hover highlighting. I tested clicks, didn't work as well.
Lua Code here
localobj= {}
obj.__index=obj-- Metadataobj.name="SandboxMouse"obj.version="1.0"obj.author="Your Name <[email protected]>"obj.homepage="https://github.com/your-repo"obj.license="MIT - https://opensource.org/licenses/MIT"-- Function to move the mouse from (x1, y1) to (x2, y2) in increments of 3 pixelsfunctionobj:moveMouse(x1, y1, x2, y2, duration)
localstepDistance=1-- Distance to move in each steplocaltotalDistance=math.sqrt((x2-x1) ^2+ (y2-y1) ^2) -- Calculate the total distance-- Prevent division by zeroiftotalDistance==0thenreturn-- No movement needed if start and end positions are the sameendlocalsteps=math.ceil(totalDistance/stepDistance) -- Calculate the number of steps neededlocaldelay= (duration/steps) *3-- Increase the delay by a factor of 3-- Log for debuggingprint("Total Distance:", totalDistance)
print("Steps:", steps)
print("Delay per Step:", delay*10e6)
-- Calculate the direction vectorlocaldx, dy=self:calculateDirection(x1, y1, x2, y2, totalDistance)
-- Function to move the mouse incrementallylocalfunctionmoveStep(stepIndex)
ifstepIndex>stepsthen-- Ensure the mouse ends up exactly at (x2, y2)hs.mouse.absolutePosition(hs.geometry.point(x2, y2))
returnend-- Calculate the new positionlocalx, y=self:calculateNewPosition(x1, y1, dx, dy, stepDistance, stepIndex)
-- Move the mouse to the calculated position using absolutePositionhs.mouse.absolutePosition(hs.geometry.point(x, y))
-- Schedule the next stephs.timer.doAfter(delay, function()
moveStep(stepIndex+1)
end)
end-- Start the movementmoveStep(1)
end-- Helper function to calculate the direction vectorfunctionobj:calculateDirection(x1, y1, x2, y2, totalDistance)
return (x2-x1) /totalDistance, (y2-y1) /totalDistanceend-- Helper function to calculate the new positionfunctionobj:calculateNewPosition(x1, y1, dx, dy, stepDistance, stepIndex)
localx=x1+dx*stepDistance*stepIndexlocaly=y1+dy*stepDistance*stepIndexreturnx, yend-- Set up hotkey for playback: Cmd+Opt+Shift+Phs.hotkey.bind({ "cmd", "alt", "shift" }, "T", function()
-- Example usage: Move the mouse from (100, 100) to (500, 500) over 2 secondsspoon.SandboxMouse:moveMouse(305, 468, 305, 1024, 0.4)
hs.alert.show("SandboxMouse:moveMouse() started")
end)
returnobj
The app just does not respond.
Apple Script
I've decided to test other solutions, and tested Apple Script. It works via using cliclick shell application.
Apple Script Code here
-- Function to calculate the square rootonsqrt(value)
return value ^0.5end sqrt
-- Custom ceiling functiononceiling(value)
if value = (value asinteger) thenreturn value asintegerelsereturn (value asinteger) +1end ifend ceiling
-- Function to move the mouse from (x1, y1) to (x2, y2) over a specified durationonmoveMouse(x1, y1, x2, y2, duration)
setstepDistanceto5-- Increase distance to move in each step for faster movementsettotalDistanceto sqrt(((x2 - x1) ^2) + ((y2 - y1) ^2)) -- Calculate the total distance-- Prevent division by zeroif totalDistance =0thenreturn-- No movement needed if start and end positions are the sameend ifsetstepsto ceiling(totalDistance / stepDistance) -- Calculate the number of steps neededsetdelayTimeto (duration / steps) *0.5-- Decrease the delay time for faster movement-- Calculate the direction vectorset {dx, dy} to calculateDirection(x1, y1, x2, y2, totalDistance)
-- Move the mouse incrementallyrepeatwithstepIndexfrom1to steps
-- Calculate the new positionset {newX, newY} to calculateNewPosition(x1, y1, dx, dy, stepDistance, stepIndex)
-- Convert newX and newY to strings for claritysetnewXStringto (newX asinteger) asstringsetnewYStringto (newY asinteger) asstring-- Move the mouse to the calculated position using the full path to cliclickdo shell script"/opt/homebrew/bin/cliclick m:"& newXString &","& newYString
-- Wait for the specified delay before the next stepdelay delayTime
end repeat-- Ensure the mouse ends up exactly at (x2, y2)do shell script"/opt/homebrew/bin/cliclick m:"& x2 &","& y2
end moveMouse
-- Helper function to calculate the direction vectoroncalculateDirection(x1, y1, x2, y2, totalDistance)
setdxto (x2 - x1) / totalDistance
setdyto (y2 - y1) / totalDistance
return {dx, dy}
end calculateDirection
-- Helper function to calculate the new positiononcalculateNewPosition(x1, y1, dx, dy, stepDistance, stepIndex)
setnewXto x1 + (dx * stepDistance * stepIndex)
setnewYto y1 + (dy * stepDistance * stepIndex)
return {newX, newY}
end calculateNewPosition
-- Example usage: Move the mouse from (305, 468) to (305, 1024) over 0.4 seconds
moveMouse(305, 468, 305, 1024, 0.4)
The text was updated successfully, but these errors were encountered:
tl;dr
Hammerspoon cannot simulate mouse movement or clicks in GeForceNow (or maybe other apps, and I don't know why, because of app implementation or full screen mode), where Apple Script works fine.
Why? Should I enable some special mode?.. Thank you for any feedback.
And thank you for work on this app! :)
Description
I'm trying to make some automation in a GeForceNow.
The application does not respond to mouse movements nor mouse clicks.
I've been testing this script to move a mouse through a menu in a game (feel free to add clicks if needed).
Menu items should react with hover highlighting. I tested clicks, didn't work as well.
Lua Code here
The app just does not respond.
Apple Script
I've decided to test other solutions, and tested Apple Script. It works via using
cliclick
shell application.Apple Script Code here
The text was updated successfully, but these errors were encountered: