<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Pradeep Jangid</title>
    <description>The latest articles on Forem by Pradeep Jangid (@prdpjngd).</description>
    <link>https://forem.com/prdpjngd</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F689948%2F4c4871d3-e5ff-4f10-8eb1-6b4066134e1b.jpeg</url>
      <title>Forem: Pradeep Jangid</title>
      <link>https://forem.com/prdpjngd</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/prdpjngd"/>
    <language>en</language>
    <item>
      <title>🧹 How to Temporarily Disable Your Mac Keyboard While Cleaning (Safe &amp; Reversible)</title>
      <dc:creator>Pradeep Jangid</dc:creator>
      <pubDate>Sat, 27 Sep 2025 05:56:37 +0000</pubDate>
      <link>https://forem.com/prdpjngd/how-to-temporarily-disable-your-mac-keyboard-while-cleaning-safe-reversible-58ja</link>
      <guid>https://forem.com/prdpjngd/how-to-temporarily-disable-your-mac-keyboard-while-cleaning-safe-reversible-58ja</guid>
      <description>&lt;p&gt;We’ve all been there — you start wiping down your MacBook keyboard and suddenly a storm of random windows open, messages get typed, and maybe even a system dialog or two pops up. 😅&lt;/p&gt;

&lt;p&gt;Wouldn’t it be nice if you could lock your keyboard temporarily while you clean it — and then unlock it with a single command?&lt;/p&gt;

&lt;p&gt;Good news: you can. In this post, I’ll show you a safe, reversible, code-only solution that works on macOS without uninstalling drivers or messing with system files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🚀 Why Not Just Smash the Power Button?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Some people shut down their Mac, but:&lt;/p&gt;

&lt;p&gt;That interrupts your workflow.&lt;/p&gt;

&lt;p&gt;You can’t see smudges properly with the screen off.&lt;/p&gt;

&lt;p&gt;And, let’s be honest — we love quick hacks.&lt;/p&gt;

&lt;p&gt;This method lets you disable only the keyboard (while keeping your Mac awake), so you can wipe away dust, crumbs, and fingerprints without worrying about accidental keypresses.&lt;/p&gt;

&lt;p&gt;🛠️ The Trick: Block All Key Events with Python&lt;/p&gt;

&lt;p&gt;We’ll use a tiny Python script with Apple’s Quartz Event Taps API (via PyObjC).&lt;br&gt;
When running, the script intercepts all key events and simply drops them.&lt;/p&gt;

&lt;p&gt;👉 Stop the script, and your keyboard comes back to life instantly.&lt;/p&gt;

&lt;p&gt;📦 Step 1 — Install the Dependency&lt;/p&gt;

&lt;p&gt;Open Terminal and install the Quartz bridge:&lt;/p&gt;

&lt;p&gt;python3 -m pip install --user pyobjc-framework-Quartz&lt;/p&gt;

&lt;p&gt;📄 Step 2 — Save the Script&lt;/p&gt;

&lt;p&gt;Create a file called disable_keyboard.py:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/env python3
# Disable Mac keyboard while cleaning
# Run: python3 disable_keyboard.py
# Stop: Ctrl+C or kill the process

from Quartz import (
    CGEventTapCreate, kCGHIDEventTap, kCGHeadInsertEventTap,
    kCGEventTapOptionDefault, kCGEventKeyDown, kCGEventKeyUp,
    kCGEventFlagsChanged, CGEventTapEnable
)
from Quartz import CFRunLoopGetCurrent, CFMachPortCreateRunLoopSource, CFRunLoopAddSource, CFRunLoopRun

def tap_callback(proxy, type_, event, refcon):
    return None  # Block every key event

mask = (1 &amp;lt;&amp;lt; kCGEventKeyDown) | (1 &amp;lt;&amp;lt; kCGEventKeyUp) | (1 &amp;lt;&amp;lt; kCGEventFlagsChanged)
tap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, mask, tap_callback, None)

if not tap:
    print("⚠️ Accessibility permission required! Enable it in System Settings &amp;gt; Privacy &amp;amp; Security &amp;gt; Accessibility.")
    exit(1)

source = CFMachPortCreateRunLoopSource(None, tap, 0)
CFRunLoopAddSource(CFRunLoopGetCurrent(), source, 0)
CGEventTapEnable(tap, True)

print("🧹 Keyboard disabled. Clean away! Press Ctrl+C to restore.")
CFRunLoopRun()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔑 Step 3 — Grant Accessibility Permission&lt;/p&gt;

&lt;p&gt;On first run, macOS will block the script unless you grant permissions:&lt;/p&gt;

&lt;p&gt;Go to System Settings → Privacy &amp;amp; Security → Accessibility.&lt;/p&gt;

&lt;p&gt;Add Terminal (or iTerm, or Python.app) to the list.&lt;/p&gt;

&lt;p&gt;Toggle it on.&lt;/p&gt;

&lt;p&gt;Now re-run the script and voilà — the keyboard is locked.&lt;/p&gt;

&lt;p&gt;⏹️ Step 4 — Unlock the Keyboard&lt;/p&gt;

&lt;p&gt;When you’re done cleaning:&lt;/p&gt;

&lt;p&gt;Press Ctrl + C in Terminal, OR&lt;/p&gt;

&lt;p&gt;In another terminal, run:&lt;/p&gt;

&lt;p&gt;pkill -f disable_keyboard.py&lt;/p&gt;

&lt;p&gt;Keyboard input is instantly restored. ✅&lt;/p&gt;

&lt;p&gt;🎯 Pro Tips&lt;/p&gt;

&lt;p&gt;Want one-click control? Wrap this script in an Automator app so you can toggle it from your dock.&lt;/p&gt;

&lt;p&gt;If you’re a power user, check out Karabiner-Elements, which lets you define profiles to disable/enable your keyboard.&lt;/p&gt;

&lt;p&gt;Always keep a mouse or trackpad handy — since this script blocks all key events, keyboard shortcuts won’t work until you stop it.&lt;/p&gt;

&lt;p&gt;📝 Conclusion&lt;/p&gt;

&lt;p&gt;Cleaning your Mac doesn’t need to feel like defusing a bomb 💣 every time you brush over a key.&lt;br&gt;
With this tiny Python hack, you can disable the keyboard temporarily, clean safely, and restore everything instantly.&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>tooling</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
