DEV Community

Cover image for I Built a Tiny macOS App So I Could Clean My Keyboard Without Accidental Typing
Mahboob
Mahboob

Posted on Edited on

I Built a Tiny macOS App So I Could Clean My Keyboard Without Accidental Typing

I Built a Tiny macOS App So I Could Clean My Keyboard Without Accidental Typing

Have you ever tried cleaning your MacBook keyboard, only to accidentally type random characters, trigger shortcuts, or change the volume?

I faced the same problem.

I wanted something simple: a way to temporarily disable my keyboard while keeping the mouse and trackpad working.

So I built Lock My Keyboard, a free, open-source macOS utility.

No complicated setup. No unnecessary features. Just Lock โ†’ Clean โ†’ Unlock.

โœจ What Does It Do?

Lock My Keyboard is designed around a simple workflow:

  • ๐Ÿ”’ One-click Lock โ€” Temporarily blocks keyboard input.
  • ๐Ÿงน Clean safely โ€” Wipe your keyboard without accidental typing.
  • ๐Ÿ–ฑ๏ธ Mouse and trackpad stay active โ€” You can still click Unlock.
  • โœ… One-click Unlock โ€” Restores normal keyboard input.
  • ๐Ÿ” Privacy-focused โ€” No accounts, cloud services, or keystroke logging.

The interface is intentionally minimal.

๐Ÿ’ป Requirements

Before installing, make sure you have:

  • An Apple Silicon Mac (M1, M2, M3, M4, or newer).
  • macOS 26 or later.
  • Homebrew installed.

๐Ÿš€ Installation Using Homebrew

Open Terminal and execute the following commands.

Step 1: Add the Homebrew tap

brew tap mahboobmonnamd/lock-my-keyboard https://github.com/mahboobmonnamd/lock-my-keyboard
Enter fullscreen mode Exit fullscreen mode

Step 2: Trust the specific cask

brew trust --cask mahboobmonnamd/lock-my-keyboard/lock-my-keyboard
Enter fullscreen mode Exit fullscreen mode

Homebrew requires explicit trust for this third-party cask. This command trusts the specific cask rather than the entire tap.

Step 3: Install the application

brew install --cask lock-my-keyboard
Enter fullscreen mode Exit fullscreen mode

Step 4: Launch the application

open -a LockMyKeyboard
Enter fullscreen mode Exit fullscreen mode

That's it!

First-Time Setup

The app requires macOS Accessibility permission to intercept keyboard events.

  1. Open Lock My Keyboard.
  2. Click Lock.
  3. If prompted, open System Settings โ†’ Privacy & Security โ†’ Accessibility.
  4. Enable permission for Lock My Keyboard.
  5. Return to the app and click Lock again.

You can now clean your keyboard and click Unlock when finished.

Important security note: The current published release (v1.0.1) is unsigned and not notarized because Apple Developer ID signing is not yet available for this project. The Homebrew cask removes the app's quarantine attribute, which bypasses normal Gatekeeper origin verification. Review the source code and verify the published release checksum before deciding to install it. This is not equivalent to Apple's notarization process.

โš™๏ธ How Does It Work?

I developed the application using:

  • Swift for the application logic.
  • SwiftUI for the user interface.
  • CoreGraphics for intercepting keyboard events.
  • macOS Accessibility APIs for the required permission checks.

The interesting part is the CoreGraphics event tap.

When you click Lock, the app creates an event tap that suppresses keyboard input, including supported media-key events, while leaving mouse and trackpad interactions available.

When you click Unlock or exit the application, the event tap is removed, allowing keyboard input again.

No keystrokes are stored or sent anywhere.

๐Ÿ› ๏ธ Building for Reliability

While building this utility, I realized that disabling keyboard input is only half the problem.

How do you know the keyboard is actually locked?

macOS can disable event taps unexpectedly. An app shouldn't continue displaying "Locked" if keyboard protection is no longer active.

To improve reliability, I've recently added:

  • Event-tap health monitoring.
  • Detection of lost Accessibility permission.
  • Clear warnings when keyboard protection unexpectedly stops.
  • Automated Swift tests.
  • GitHub Actions CI.
  • Safer release and Homebrew validation.

These improvements are merged into the source code and are intended for an upcoming release. The latest published version remains v1.0.1.

โค๏ธ Why Open Source?

This started as a small personal utility, but I believe useful software doesn't always need to be complicated.

Sometimes the best projects solve one everyday problem really well.

Lock My Keyboard is free, open source, and available on GitHub.

GitHub Repository:

https://github.com/mahboobmonnamd/lock-my-keyboard

Installation Guide:

https://github.com/mahboobmonnamd/lock-my-keyboard/blob/main/docs/INSTALL.md

Latest Published Release:

https://github.com/mahboobmonnamd/lock-my-keyboard/releases/tag/v1.0.1

๐Ÿ™Œ Feedback and Contributions Welcome!

If you find this useful, give it a try and share your feedback.

If you're a macOS or Swift developer, contributions, bug reports, and improvement suggestions are always welcome.

And if you like the project, consider giving it a โญ on GitHub!


Built with Swift, SwiftUI, and the motivation to solve one small, annoying everyday problem.

Top comments (0)