Return to site

Bettertouchtool 2 332 – Customize Multi Touch Trackpad Gestures Copy

broken image


BetterTouchTool 3.401 - Customize multi. BetterTouchTool adds many new, fully customizable gestures to the Magic Mouse, Multi-Touch MacBook trackpad, and Magic Trackpad. These gestures are customizable: Magic Mouse: Pinch in / out (zoom). BetterTouchTool is a third party app that lets you create custom gestures for your Mac's trackpad. BetterTouchTool does require a license (personal licenses are available from £4.00) but a free 45 day free trial is available, so you can try before you buy. BetterTouchTool 2.332 – Customize multi-touch trackpad gestures. January 27, 2018 BetterTouchTool adds many new, fully customizable gestures to the Magic Mouse, Multi-Touch MacBook trackpad, and Magic Trackpad. That's where BetterTouchTool comes in handy. This powerful utility gives you total control over all of your Mac's input devices, including a touchpad, Touch Bar, mouse, and keyboard. How to customize Mac gestures and shortcuts. A customizer's dream, the app serves as your personal HQ for inputs.

Bettertouchtool 2 332 – Customize Multi Touch Trackpad Gestures Copy Paste

Bettertouchtool 2 332 – Customize Multi Touch Trackpad Gestures Copy

Funny enough, I actually did all of this work a while ago, before apple announced their new trackpad thingy.

Many people who use the Magic Trackpad (or the Macbook's trackpad) prefer to do a two finger click instead of a right mouse click. Let me preface by saying, I am not one of you. I like myself a good ol' fashion right mouse click. Like the computer gods intended.

All sacrilege aside, I have always been really pissed about how Apple hasn't been able to get their act together when it comes to a right mouse click. Allow me to defend my claim. This is the Magic Trackpad

Bettertouchtool 2 332 – Customize Multi Touch Trackpad Gestures Copy Software

It is beautiful and lovely (if you ignore my shadow). And quite large, which I like. I can comfortably stretch my hand over the trackpad and scroll, swipe, pinch, etc with no problems whatsoever. I tend to keep my hand in the center of this giant thing. And this is a picture where a piece of paper is covering the part of the trackpad that is recognized as a right click

Bettertouchtool 2 332 – customize multi touch trackpad gestures copy software

Funny enough, I actually did all of this work a while ago, before apple announced their new trackpad thingy.

Many people who use the Magic Trackpad (or the Macbook's trackpad) prefer to do a two finger click instead of a right mouse click. Let me preface by saying, I am not one of you. I like myself a good ol' fashion right mouse click. Like the computer gods intended.

All sacrilege aside, I have always been really pissed about how Apple hasn't been able to get their act together when it comes to a right mouse click. Allow me to defend my claim. This is the Magic Trackpad

Bettertouchtool 2 332 – Customize Multi Touch Trackpad Gestures Copy Software

It is beautiful and lovely (if you ignore my shadow). And quite large, which I like. I can comfortably stretch my hand over the trackpad and scroll, swipe, pinch, etc with no problems whatsoever. I tend to keep my hand in the center of this giant thing. And this is a picture where a piece of paper is covering the part of the trackpad that is recognized as a right click

What the hell. Why is it that on this giant beast of a trackpad, there's less than one square inch of a right click region? That is completely useless, which is why so many people go with a two finger click, or control clicking. Not me. Instead, i spend way too much time fighting against the man.

So my solution to the problem was to write an application to make it so the whole right half of the trackpad is recognized as a right click. AKA, making the magic mouse work the way it should have to begin with.

I'm going to assume at this point that you understand the basics of the event tap. if you don't, go read this. It was originally going to be part of this post, but it got a little long.

Apples Private Multi Touch API

Bettertouchtool 2 332 – Customize Multi Touch Trackpad Gestures Copy Shortcut

Private doesn't have to mean scary. Just undocumented, and not really intended for anyone else to know about/use. 🙂

If you link in Apple's multi touch api, and you have the right headers, you can do some pretty neat things. Most of what I know on the subject came from pouring over the source of FingerMgmt. I started off by looking for an existing tool such as BetterTouchTool or MagicPrefs to see if I could accomplish my goal, but was quickly underwhelmed. If you want to be able to have gestures to play/pause, skip, previous, run an apple script or all sorts of other crazy things, BetterTouchTool or MagicPrefs has got you covered. But if you want to just make the right half of the track pad be recognized as a right click, you're out of luck.

But in one of the windows buried deep inside one of those two apps (don't remember which) I found a vague reference to FingerMgmt, and I spent some time looking at the source. It's pretty complex as it relies on you having some knowledge about the subject ahead of time, but that's ok.

You need to get yourself a copy of the multi touch headers. I think that I ended up with a self-modified version. I think it came from a mix of this github, and FingerMgmt. But I did this so long ago that I'm not positive.

With the header added to your Xcode project, you need to link to /System/Library/PrivateFrameworks/MultitouchSupport.framework

With all that in place, you can hook into the multi touch to recognize when a user touches the trackpad.

2
4
6
8
10
{
MTDeviceRef device=MTDeviceCreateFromDeviceID(device_id);
MTRegisterContactFrameCallback(device,touchCallback);
}
voidtouchCallback(MTDeviceRef device,MTTouch touches[],size_t numTouches,doubletimestamp,size_t frame)
}

This will get a reference to the device you want to monitor, add touchCallback as a function to execute when stuff happens, and then start monitoring the multi touch frame. Unfortunately, the multi touch framework will only tell you information about the touches, it doesn't tell you when clicks happen – which is why you need to know about the event loop. Also in this code chunk I got my device by it's ID. I just happened to know (from debugging) that for me it's 0x400000015dd4d84. I assume these are unique. You could certainly hook up to all multi touch devices in a loop with MTDeviceCreateList or if you're on a macbook MTDeviceCreateDefault should always give you the one that's built into the laptop that way you'd never have to go through the trouble of debugging to figure out what your trackpad's id is.

The App

The app I threw together is really quite simple. Everything can fit in the app delegate.
I put Application isagent(UIElement):YES inside my info.plist so that nothing shows up in the dock. At runtime, I created a menu item with an Enable/Disable and Quit button. This allows me to disable the app if I ever have the need. This comes in handy when something causes the event loop to be upset with my app.

I tied into the multi touch framework with this callback

2
4
6
8
10
12
voidtouchCallback(MTDeviceRef device,MTTouch touches[],size_t numTouches,doubletimestamp,size_t frame)
shouldTransformClick=NO;
{
floatx=touch->normalizedVector.position.x;
{
}
}

if there's only one touch, and that touch is on the right half of the trackpad, I set a static bool to YES so that the event tap piece knows to transform any left click into a right click.

Note that the normalizedVector.position.x and normalizedVector.position.y points are a 0 to 1 scale.

My event tap looks like this

Bettertouchtool 2 332 – Customize Multi Touch Trackpad Gestures Copy Windows 10

2
4
6
8
10
12
14
16
18
20
22
24
26
28
CGEventRef handleCGEvent(CGEventTapProxy proxy,CGEventType type,CGEventRef eventRef,void*refcon)
if(shouldTransformClickNO)
returneventRef;
if(type!=kCGEventLeftMouseUp&&type!=kCGEventLeftMouseDown)
returneventRef;
NSEvent*event=[NSEvent eventWithCGEvent:eventRef];
{
}
CGEventSourceRef sourceRef=CGEventCreateSourceFromEvent(eventRef);
CGEventRef newRef;
{
newRef=CGEventCreateMouseEvent(sourceRef,kCGEventRightMouseDown,point,kCGMouseButtonRight);
else
newRef=CGEventCreateMouseEvent(sourceRef,kCGEventRightMouseUp,point,kCGMouseButtonRight);
}

As you can see right off, I didn't set up the mask like I should have when i tied into the event tap, so i filter out the undesired events manually. This is something i'm going to go back and fix, but i don't feel the need to update the code here.

After filtering out the event types i don't care about, i check that the event came from the HID device with the same ID as my magic trackpad.

When I want to turn the left click into a right click, I create a new mouse event and return the new right click event from my event handler. This will make everything else act as though I had made a right click.

There have been a few issues with this here and there, but they happen pretty infrequently. Whenever I do have problems, I tend to just disable the app, do what I need, and then enable it again.

Rather than supply all of the source in this post, I thought I'd just supply the Xcode project. Keep in mind that since this was a personal project, I didn't spend too much time making the code beautiful.

It started off as a project named MouseFun. And then I renamed it to RCR because it fit nicely in my menu bar. Though Honestly I forgot what RCR stood for. I think it was… Right Click….. something that starts with the letter R.

Hope someone else out there finds this useful.





broken image