1.0.3 • Published 12 months ago
electron-trackpad-utils v1.0.3
electron-trackpad-utils
Trigger trackpad haptic feedback and get trackpad scroll began, scroll ended, and force click events in Electron on macOS.
Installing
npm install electron-trackpad-utilsAPI
onTrackpadScrollBegan(callback) (macOS only)
callbackFunction
This fires when the user starts dragging touches on the trackpad.
onTrackpadScrollEnded(callback) (macOS only)
callbackFunction
This is triggered when the touches end during scrolling. This may be different from when the scroll events sent to the browser end, in the case of inertial scrolling.
onForceClick(callback) (macOS only)
callbackFunction
triggerFeedback() (macOS only)
Triggers haptic feedback on the MacBook's built-in trackpad or Magic Trackpad. For example, trigger feedback when snapping to alignment while dragging an object.
Usage
In main process:
const { BrowserWindow } = require("electron");
const trackpadUtils = require("electron-trackpad-utils");
trackpadUtils.onTrackpadScrollBegan(() => {
	console.log("onTrackpadScrollBegan");
});
trackpadUtils.onTrackpadScrollEnded(() => {
	console.log("onTrackpadScrollEnded");
});
trackpadUtils.onForceClick(() => {
	console.log("onForceClick");
});
function createWindow() {
	const mainWindow = new BrowserWindow({
		height: 500,
		width: 800,
	});
	mainWindow.webContents.loadFile("index.html");
	setInterval(() => {
		trackpadUtils.triggerFeedback();
	}, 3000);
}
app.whenReady().then(() => createWindow());How to Run Demo
After cloning this repository, run:
npm install
npm rebuild
cd demo
npm install
npm startLicense
MIT License