Writing a Keyboard Disabler for macOS | Al Idian
Writing a Keyboard Disabler for macOS
2026-06-18
What did I make?
Whenever I wipe down my laptop keyboard, I prefer to disable the keys first.<br>There are apps that can do this, but none of them are a good fit for me: some are paid, some are closed source, and some do far more than I need.
heel is a small tool that deals with this problem.<br>It is command-line only and is packaged as a script that can be downloaded from GitHub and run without installation.
Running heel disables all keyboard input, including special keys like brightness and volume.<br>To re-enable the keyboard, press ctrl + c.
heel requires macOS Accessibility permission.<br>For a short usage guide, see the readme here.
Implementation details
heel works by creating a CGEventTap — a low-level hook into macOS’s input event pipeline provided by the CoreGraphics framework.<br>The tap sits at the Human Interface Device (HID) level and intercepts keyboard events before they reach any application.<br>When an event arrives, the callback tells the system to discard it.
Rather than depend on a third-party library, heel calls into the CoreGraphics and CoreFoundation system frameworks directly using Python’s built-in ctypes module.<br>This keeps the tool dependency-free.
The callback is wrapped in a ctypes.CFUNCTYPE object, which must be kept alive for as long as the tap is active.<br>If it is garbage-collected, the callback pointer becomes invalid and the program will crash.<br>To prevent this, heel holds an explicit reference to the object.
The ctrl + c escape hatch is implemented inside the callback itself rather than as a signal handler.<br>When a key-down event arrives, heel checks whether the key is c and whether the control modifier flag is set.<br>If so, it calls CFRunLoopStop to exit the run loop and proceed to re-enable the keyboard.<br>All other key events are swallowed.
Limitations of this tool include:
It is macOS only.<br>The CGEventTap API is specific to macOS.
ctrl + c cannot be suppressed.<br>By design, there must be a way to escape.
Accessibility permission is required.
The case for small tools
heel is short enough to read in a few minutes and has no dependencies beyond Python’s standard library.<br>Being open source, users can verify what it does before granting it Accessibility permission.<br>Since input monitoring is involved, this is a reasonable thing to want.
Small, focused tools tend to be easier to trust for this reason.<br>When the scope is narrow and the source is available, there is nothing to take on faith.