Hammerspoon / hammerspoon

Staggeringly powerful macOS desktop automation with Lua
http://www.hammerspoon.org
MIT License
12.1k stars 582 forks source link

Proposal: hs.eventtap.event:getAllTouches #2470

Open CantGetRight82 opened 4 years ago

CantGetRight82 commented 4 years ago

I am able to use an event tap to get to raw touch events (eventType = 29) From earlier Cocoa projects, I have learned that you can get to the touch locations by using:

[NSEvent eventWithCGEvent:event].allTouches

I have not found a way to get to the individual touches from Hammerspoon. The proposal is to add a method getAllTouches(event) to the hs.eventtap.event extension, that returns the corresponding touches.

All feedback is appreciated.

asmagill commented 4 years ago

It will probably be a couple of days, but that looks interesting... and is actually something I looked for a while back and didn't find... I'll look into it, unless you were suggesting that you might want to add it yourself?

CantGetRight82 commented 4 years ago

Nice, I was sort of prepared to do the work myself. I am not used to bridging to and from lua, so it will probably take me a longer time. But I can definitely give it a go.

asmagill commented 4 years ago

It's not hard, I started myself with the third edition of _Programming_InLua described at https://www.lua.org/docs.html.

That said, we do tend to use a special framework created by @cmsj in conjunction with Hammerspoon called LuaSkin that simplifies some aspects, adds some checks for us automatically, and allows for creating conversion functions that convert back and forth between lua userdata/tables and Objective-C objects... unfortunately it's not really documented, outside of it's own source.

I've tried putting together a module builders walkthrough before that goes into where and how LuaSkin can be used to simplify module building, but got distracted and haven't finished... I'll see if I can dig it up and maybe give it another go. After I look into this (you have possibly provided a way to get at something that's niggled in the back of my brain for a while now!)

CantGetRight82 commented 4 years ago

If I understand correctly, you are already taking this on? Probably for the best, but otherwise just let me know. I really want this too ;-)

asmagill commented 4 years ago

Yes, I will. But I also don't want to discourage you from your own contributions should another idea come to you in the future, which is why I'll also take another crack at working out some documentation for LuaSkin and module builders. But, yes, this particular idea is related to one I've been mulling for a while and I'd like to see it through.