lokxii / Mac-trackpad-mapper

A utility for Mac that maps finger position on trackpad to cursor location on Scnreen
MIT License
28 stars 3 forks source link

Mouse click event #10

Closed e-su closed 1 year ago

e-su commented 1 year ago

Hello, I want to tap the left side of the trackpad to simulate the left mouse button, to tap the right side to simulate the right mouse button, how can I modify the code? I want use this to play Muse Dash on Mac with trackpad. Thank you very much.

lokxii commented 1 year ago

All the logic handling finger and cursor movement happens in trackpadCallback in trackpad_mapper_util.c

The function receives an array of finger data including which finger is touching the trackpad, how hard it is pressing, how fast it is moving, etc

Note that the data doesn't tell you a finger tapped, but you can guess it by interpreting MTTouch.state field.

You will need to for each finger data

  1. interpret if it is a new finger tapping the trackpad, an existing finger moving or leaving the trackpad
  2. Check its coordinates (on the left or on the right)
  3. post corresponding CG mouse event

Actually I have tried doing similar thing on a local branch that wasn't pushed to github. I wanted yo tap on trackpad to generate z and x key presses to play osu but I couldn't get it working consistently.

I don't really recommend doing this because the latency is unknown and probably inconsistent. I never did a benchmark measuring time from MTTouch triggering callback to an application receiving mouse move event but you may want to try it.

e-su commented 1 year ago

I tried mouse click events and keyboard key events, but it didn't work as expected, sometimes tapping the trackpad didn't respond, sometimes tapping the trackpad repeated the output. I have no idea.

lokxii commented 1 year ago

I will push my code to github after fixing bug in SO-copy-pasted code

lokxii commented 1 year ago

Go checkout tapping branch (generateClick()) to see how I implemented tapping. It is not what you want but you can see how I interpret finger states

e-su commented 1 year ago

I implemented tapping the left or right side of the trackpad to generate the specified event. Appreciate it.