Error moving mouse to location

107 views
Skip to first unread message

Jonathan Zwi

unread,
Aug 30, 2020, 2:05:42 PM8/30/20
to Hammerspoon

I am trying to set mouse coordinates in order to call hs.eventtap.leftClick() at various locations, however I am struggling.

I am able to click at the starting coordinate:

   local cursorLocation = hs.mouse.getAbsolutePosition()
   hs.eventtap.leftClick(cursorLocation)

but unable to properly move the mouse after this initial click.

I have tried various alternatives, but none are working.  Where is my error?

Variation 1a
   hs.mouse.setAbsolutePosition(cursorLocation.x+100, cursorLocation.y+100)

Variation 1b
   hs.eventtap.leftClick(cursorLocation.x+100, cursorLocation.y+100 )


I am not even able to successfully specify the point coordinates​​)
​Variations 2a
   hs.mouse.setAbsolutePosition(​100, 100)

​Variations 2​b​
   hs.eventtap.leftClick(100, 100)

Thanks for any help.




Adrian Chung

unread,
Oct 19, 2020, 2:30:43 PM10/19/20
to Hammerspoon
The hs.mouse.setAbsolutePosition and setRelativePosition take a 'point' table as the argument, so you need to try this instead:

  hs.mouse.setAbsolutePosition({x=100,y=100})

Or you can do:

   hs.mouse.setAbsolutePosition({x=cursorLocation.x+100,y=cursorLocation.y+100})

That will work for you!

Jonathan Zwi

unread,
Oct 19, 2020, 3:34:55 PM10/19/20
to Adrian Chung, Hammerspoon

Adrian,

I ultimately found a different solution, but thanks for the response—seems I just needed to add the curly brackets!

Best,
Jonathan



--
You received this message because you are subscribed to a topic in the Google Groups "Hammerspoon" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/hammerspoon/1KRR-IAiI4o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to hammerspoon...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/hammerspoon/0f613f70-9826-4466-a2f5-6bcbf6edf932n%40googlegroups.com.


--
Reply all
Reply to author
Forward
0 new messages