
Security News
Bun 1.2.19 Adds Isolated Installs for Better Monorepo Support
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
input-trakr
Advanced tools
Native macOS input monitoring for trackpad gestures, mouse, and keyboard events with separate event emitters
A comprehensive native Node.js addon for monitoring trackpad gestures, mouse events, and keyboard input on macOS. Perfect for Electron applications that need to capture global input events.
npm install macos-input-monitor
const { inputMonitor } = require('macos-input-monitor');
// Check and request accessibility permissions
if (!inputMonitor.checkAccess()) {
inputMonitor.requestAccess();
}
// Set up event listeners
inputMonitor.on('gesture', (data) => {
console.log(`Gesture: ${data.type} ${data.direction}`);
});
inputMonitor.on('mousedown', (data) => {
console.log(`Mouse down: ${data.button} at (${data.x}, ${data.y})`);
});
inputMonitor.on('keydown', (data) => {
console.log(`Key pressed: ${data.key}`);
});
// Start monitoring
inputMonitor.start();
// Stop monitoring when done
process.on('SIGINT', () => {
inputMonitor.stop();
process.exit(0);
});
start(options?)
Start monitoring input events.
inputMonitor.start({
enableGestures: true, // Monitor trackpad gestures
enableMouse: true, // Monitor mouse events
enableKeyboard: true // Monitor keyboard events
});
stop()
Stop monitoring input events.
checkAccess()
Check if accessibility permissions are granted.
requestAccess()
Request accessibility permissions (shows system dialog).
inputMonitor.on('gesture', (data) => {
// data.type: 'swipe' | 'pinch' | 'rotate'
// data.direction: 'left' | 'right' | 'up' | 'down' | 'in' | 'out' | 'clockwise' | 'counterclockwise'
// data.fingerCount: number of fingers detected
// data.deltaX, data.deltaY: movement deltas
// data.magnification: pinch scale factor
// data.rotation: rotation angle
});
inputMonitor.on('mousedown', (data) => {
// data.button: 'left' | 'right' | 'middle' | 'button4' | 'button5'
// data.clickType: 'single' | 'double' | 'triple'
// data.x, data.y: cursor position
});
inputMonitor.on('mouseup', (data) => {
// Same structure as mousedown
});
inputMonitor.on('mousemove', (data) => {
// data.type: 'mousemove' | 'mousedrag'
// data.direction: 'left' | 'right' | 'up' | 'down'
// data.deltaX, data.deltaY: movement deltas
// data.isDrag: boolean for drag operations
});
inputMonitor.on('scroll', (data) => {
// data.button: 'trackpad' | 'wheel'
// data.direction: scroll direction
// data.deltaX, data.deltaY: scroll deltas
});
inputMonitor.on('keydown', (data) => {
// data.key: 'A' | 'Enter' | 'Shift' | 'ArrowUp' | etc.
// data.keyCode: raw key code
// data.modifiers: 'Control+Shift' | 'Meta+Alt' | etc.
// data.isRepeat: boolean for key repeat
});
inputMonitor.on('keyup', (data) => {
// Same structure as keydown
});
inputMonitor.on('modifier', (data) => {
// data.key: 'Control' | 'Shift' | 'Meta' | 'Alt' | etc.
// data.isPressed: boolean for press/release state
});
const { MacOSInputMonitor } = require('macos-input-monitor');
const monitor = new MacOSInputMonitor();
monitor.on('gesture', handleGesture);
monitor.start();
// In your main process
const { app, BrowserWindow } = require('electron');
const { inputMonitor } = require('macos-input-monitor');
app.whenReady().then(() => {
// Request permissions on app start
if (!inputMonitor.checkAccess()) {
inputMonitor.requestAccess();
return;
}
// Set up global gesture handling
inputMonitor.on('gesture', (data) => {
if (data.type === 'swipe' && data.direction === 'left') {
// Handle back navigation
BrowserWindow.getFocusedWindow()?.webContents.goBack();
}
});
inputMonitor.start({ enableGestures: true });
});
app.on('before-quit', () => {
inputMonitor.stop();
});
try {
inputMonitor.start();
} catch (error) {
if (error.message.includes('Accessibility permissions')) {
console.log('Please grant accessibility permissions');
inputMonitor.requestAccess();
} else if (error.message.includes('already active')) {
console.log('Monitoring is already running');
}
}
# Install dependencies
npm install
# Build native addon
npm run build
# Run tests
npm test
npm run build
to compile the native moduleMIT License - see LICENSE file for details.
FAQs
Native macOS input monitoring for trackpad gestures, mouse, and keyboard events with separate event emitters
We found that input-trakr demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
Security News
Popular npm packages like eslint-config-prettier were compromised after a phishing attack stole a maintainer’s token, spreading malicious updates.
Security News
/Research
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.