New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow hs.eventtap.event.newMouseEvent() to accept mouseMoved #2144
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't test it right now, but the code and approach looks sound.
I'll try and download the pull later tonight and give it a real test then.
Hmm... can confirm that it's not working... But this does: delta = 100
foo= hs.eventtap.event.newEvent()
foo:setType(hs.eventtap.event.types.mouseMoved)
mouseAt = hs.mouse.getAbsolutePosition()
mouseAt.y = mouseAt.y + delta
foo:location(mouseAt)
foo:post() as does this (after the pull, didn't try it before applying the pull): delta = 100
mouseAt = hs.mouse.getAbsolutePosition()
mouseAt.y = mouseAt.y + delta
hs.eventtap.event.newMouseEvent(hs.eventtap.event.types.mouseMoved, mouseAt):post() Looks like the important part is setting the location to the destination rather than adjusting the delta properties. I suppose that the deltas might be nice if we think something else might be looking at the events we're posting. Not sure if you want to code a specific helper function for moving the mouse based on these new findings or land this as is, since it is a better implementation when creating a move event with no button press associated. |
So I'm the one who brought this up in IRC. I'm trying to use Hammerspoon to automate mouse movements within a game built on Unity, which seems to center the mouse on the screen. I tried both examples (I think the second one only works with the patch), and neither worked in the game. That being said, I was able to get Karabiner's mouse movement to work fine in-game. I suspect we need to be able to manipulate the mouse delta directly to get results here (as opposed to selecting a mouseAt position), but I could be wrong. Any thoughts? |
You could try throwing the delta in anyways, even if traditional mouse movement doesn't require it, and see if it help with your specific situation. Otherwise I suspect we're just not injecting the event early enough into the stream and KE is probably the way to go. Something like this: delta = 100
foo= hs.eventtap.event.newEvent()
foo:setType(hs.eventtap.event.types.mouseMoved)
mouseAt = hs.mouse.getAbsolutePosition()
foo:setProperty(hs.eventtap.event.properties.mouseEventDeltaY, delta)
mouseAt.y = mouseAt.y + delta
foo:location(mouseAt)
foo:post() |
@asmagill - that worked! Thanks for looking at this. |
@asmagill thoughts on landing this PR anyway, so people can create a |
It might have been lost in the dialog, but an earlier question I posed is should we land this as is, or do you also want to add a helper function for mouse movement from the current position that also takes a table with x and y specified and preset the new location and delta's? With this pull as it is, @shayanjm would have to do the following: delta = 100
mouseAt = hs.mouse.getAbsolutePosition()
mouseAt.y = mouseAt.y + delta
myEvent = hs.eventtap.event.newMouseEvent(hs.eventtap.event.types.mouseMoved, mouseAt)
myEvent:setProperty(hs.eventtap.event.properties.mouseEventDeltaY, delta):post() It might be nice to have a constructor specifically for mouse movement, something like:
Where Of course, this then suggests a companion Your call; as is, the new pull is still easier then creating the event completely from scratch, but we should probably document somewhere in here that creating mouse movement that other apps can see is a two step process -- |
It's worth noting that for this specific application, I ended up setting |
I'm going to merge this as-is, and maybe we can circle back to add an |
@asmagill someone on IRC brought up a question about how to send mouse movements with
hs.eventtap
and in digging around with themouseEventDeltaX
property, I can't get it to work.I've tried both:
and (with this PR applied):
but neither seems to cause the mouse pointer to actually move.
Am I doing something wrong, or is this broken somehow?