mac-precision-touchpad
mac-precision-touchpad copied to clipboard
Userspace implementation of three-finger-drag via WM_INPUT and mouse_event
Issue
Windows Precision Touchpad implementation lacks the logic of three-finger drag, and since this driver project is merely a translation layer to connect to the Precision-Touchpad interface it is impossible to implement it driverside.
Solution
Have a userspace program that monitors WM_INPUT messages in the background and synthesize mouse_event calls. The program should also allow one-click disabling of all Precision-Driver three-finger gestures as not to cause interference.
Implementation Sketch
- Userspace program configures Precision Driver options to "Do Nothing" for all three-finger gestures
- Userspace program calls RegisterRawInputDevices with the correct usage (need to verify, I believe it should be DIGITIZER:TOUCHPAD), and with RIDEV_INPUTSINK (monitor in background) + RIDEV_DEVNOTIFY (listen for pertinent device change) flags
- Upon receiving WM_INPUT_DEVICE_CHANGE arrival notices, userspace program calls GetRawInputDeviceInfo for each handle received to identify which handle belongs to the device that we wish to monitor, then fetch the preparsed data for that device via another GetRawInputDeviceInfo call.
- For each incoming WM_INPUT message:
- Call GetRawInputData with flag RID_HEADER to check that the handle belongs to the device we wish to monitor, discard if not.
- Call GetRawInputData with flag RID_INPUT to fetch the content for the messages coming from the monitored device
- Use the preparsed data to interpret the touch state, evaluate whether user is interacting with the three-finger-drag gesture
- synthesize the corresponding motion and action (accounting for user sensitivity preferences) using mouse_event, which broadcasts mouse motion rather than sending them to a specific app as SendInput would.
- NOTE: mouse_event cannot send to higher-privilege processes, so in order to interact with elevated windows the Userspace program must be launched with the same or higher privileges. Installing the userspace process as a background service with SYSTEM privileges should account for all possible interactions.
Extension
- The ability to monitor for raw touch states in userspace enables the possibility of identifying 5~10 finger gestures without interfering with regular Precision Touchpad opreations.
- Additionally, a temporary driver switch (maybe accessed via hotkey) could potentially enable pointer-mode for tablet-like drawing.
Sample UX proof-of-concept:
Alternatively, instead of a hotkey switch, can just detect five finger as "quick jot mode" and the sixth finger acting as absolute-coordinate drawing within the region subset:
cool!!!
Hi, I developped an app that does exactly this, enabling three fingers drag on any Windows Precision compatible touchpad: https://github.com/ClementGre/ThreeFingersDragOnWindows.