npm.io
1.0.1 • Published 2d ago

macos-haptic

Licence
MIT
Version
1.0.1
Deps
1
Size
8 kB
Vulns
0
Weekly
0
Stars
1
Install scriptsThis package runs scripts during installation (preinstall/install/postinstall)

macos-haptic

Native Node.js addon for macOS trackpad haptic feedback (Taptic Engine). Also exposes trackpad pressure and finger presence data via the MultitouchSupport private framework. You can see it in a project here, but obviously the only way to experience it is via touch.

Requirements

  • macOS 10.11+
  • Node.js >= 18
  • Xcode Command Line Tools (xcode-select --install)

Install

npm install macos-haptic

The native addon compiles on npm install via node-gyp.

API

perform(pattern?)

Triggers a single haptic feedback tap.

const { perform } = require('macos-haptic');
perform('generic');

pattern <string> — One of: 'generic' (default), 'alignment', 'levelChange'.

burst(count?, pattern?)

Triggers count rapid haptic taps of the same pattern.

const { burst } = require('macos-haptic');
burst(3, 'alignment');

count <number> — Number of taps. Default: 5.

allBurst(count?)

Cycles through all patterns count times.

const { allBurst } = require('macos-haptic');
allBurst(2);
getPressure()

Returns the current trackpad pressure as a float (0.0 – ~1.0). Requires a compatible Force Touch trackpad.

const { getPressure } = require('macos-haptic');
console.log(getPressure());
isFingerPresent()

Returns true if a finger is currently detected on the trackpad.

const { isFingerPresent } = require('macos-haptic');
console.log(isFingerPresent());
patterns

Array of valid pattern names: ['generic', 'alignment', 'levelChange'].

Credit

Massive shoutout to Kyome22's OpenMultitouchSupport, whose code was instrumental in the detection of finger presence.

License

MIT

Keywords