macos-cgeventtap-rust

Intercept macOS input events and simulate key/mouse actions with Rust CGEventTap.

1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/hafley66/claude-research --skill macos-cgeventtap-rust
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: macos-cgeventtap-rust
Source: https://github.com/hafley66/claude-research/tree/main/skills/macos-cgeventtap-rust
Command: npx skills add https://github.com/hafley66/claude-research --skill macos-cgeventtap-rust

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill demonstrates how to set up a system-wide input interception mechanism on macOS using Rust, bridging high-level Rust code with macOS CoreGraphics event taps to monitor and optionally simulate input events.

Core Features & Use Cases

  • Setup and run CGEventTap in a background thread with CFRunLoop integration.
  • Implement mutable state in the callback via static, Arc<Mutex<_>>, or channels for robust multi-listener patterns.
  • Support double-click detection, key/mouse event simulation, and proper teardown with permission handling.

Quick Start

Run the Rust-based macOS event tap example to start intercepting input.

Frequently Asked Questions about macos-cgeventtap-rust

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I monitor system-wide keyboard and mouse input on macOS using Rust?

You can monitor system-wide keyboard and mouse input on macOS using Rust by implementing a CGEventTap within a background thread and integrating it with a CFRunLoop to intercept events globally.

How does CGEventTap handle mutable state in an asynchronous Rust callback?

CGEventTap handles mutable state in an asynchronous Rust callback by utilizing thread-safe patterns such as static variables, Arc<Mutex<_>>, Cell, or channels to support robust multi-listener event processing.

Can I simulate key and mouse events while intercepting input on macOS?

Yes, you can simulate key and mouse events while intercepting input on macOS by configuring the Rust CGEventTap callback to both monitor and inject synthetic input events into the system run loop.

Do I need special permissions to run a macOS event tap for input monitoring?

Yes, macOS input monitoring requires specific accessibility and input permissions, which must be properly handled and requested during the CGEventTap setup to ensure the system allows event interception.

What is the best way to ensure safe teardown of a macOS event tap in a Rust run loop?

The best way to ensure safe teardown of a macOS event tap in a Rust run loop is to follow robust teardown patterns that properly stop the CFRunLoop and clean up the CGEventTap resources without crashing.

Why does my Rust macOS event tap stop working or fail to intercept double-clicks?

A Rust macOS event tap may fail to intercept double-clicks if the mutable state logic is not thread-safe or if proper CFRunLoop integration and teardown patterns are not implemented correctly within the callback.