Skip to content

Instantly share code, notes, and snippets.

@oitan
Created June 5, 2026 12:48
Show Gist options
  • Select an option

  • Save oitan/006df761ad57ce1ed237dfadce3fbfd9 to your computer and use it in GitHub Desktop.

Select an option

Save oitan/006df761ad57ce1ed237dfadce3fbfd9 to your computer and use it in GitHub Desktop.
Karabiner-Elements Cleaning Mode for macOS — toggle a keyboard-disable lock with a 3-second hold so you can wipe down your Mac keyboard without typing anything

Karabiner-Elements Cleaning Mode (macOS)

A Karabiner-Elements complex modification that turns your Mac keyboard into a brick on demand — useful when wiping down keys without typing gibberish into whatever app has focus.

What it does

  • Hold right_shift + right_command for 3 seconds → cleaning mode ON, all keyboard input is swallowed
  • Hold the same combo again for 3 seconds → cleaning mode OFF
  • macOS notification fires on each toggle so you know the state

While active, the following input is dropped:

  • All standard key_code events (letters, numbers, modifiers, function keys, arrows, etc.)
  • consumer_key_code (media keys, brightness, volume)
  • apple_vendor_top_case_key_code / apple_vendor_keyboard_key_code (the fn key and other Apple-specific top-case keys)

What it does NOT block

Karabiner-Elements cannot intercept these on macOS, so they still work during cleaning mode:

  • Trackpad / built-in Magic Trackpad clicks and movement — Apple's internal pointing devices bypass Karabiner's virtual HID driver. If you need pointer events blocked too, lock the screen (Ctrl + Cmd + Q) before wiping, or use Hammerspoon's eventtap API.
  • Power button, Touch ID — handled by SMC / Secure Enclave below the OS layer.

Why a 3-second hold?

The toggle combo itself has to survive the catch-all blocker, so it needs to be something you won't fat-finger while cleaning. Two pinky keys held simultaneously for 3 seconds is hard to trigger by accident with a microfiber cloth.

Requirements

  • macOS (tested on Darwin 24.x / Sequoia)
  • Karabiner-Elements installed and granted Input Monitoring permission

Install

  1. Open ~/.config/karabiner/karabiner.json
  2. Paste the rule from cleaning-mode.json into your profile's complex_modifications.rules array
  3. Save — Karabiner-Elements reloads automatically

Or import via the Karabiner-Elements UI: Settings → Complex Modifications → Add predefined rule → Import more rules from the Internet, then paste the JSON.

Tip: also lock the screen

If you want trackpad clicks neutralized too, add a shell_command to the ON-toggle manipulator:

{ "shell_command": "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -suspend" }

The login screen ignores keyboard and pointer input until you type your password, so the whole machine becomes safe to wipe.

{
"description": "Cleaning Mode: hold right_shift+right_command for 3s to toggle. Blocks all keys while active.",
"manipulators": [
{
"type": "basic",
"from": {
"simultaneous": [
{ "key_code": "right_shift" },
{ "key_code": "right_command" }
],
"simultaneous_options": {
"key_down_order": "insensitive",
"key_up_order": "insensitive"
},
"modifiers": { "optional": ["any"] }
},
"to_if_held_down": [
{ "set_variable": { "name": "cleaning_mode", "value": 1 } },
{ "shell_command": "osascript -e 'display notification \"Cleaning mode ON — keys blocked\" with title \"Karabiner\" sound name \"Glass\"'" }
],
"parameters": {
"basic.to_if_held_down_threshold_milliseconds": 3000
},
"conditions": [
{ "type": "variable_if", "name": "cleaning_mode", "value": 0 }
]
},
{
"type": "basic",
"from": {
"simultaneous": [
{ "key_code": "right_shift" },
{ "key_code": "right_command" }
],
"simultaneous_options": {
"key_down_order": "insensitive",
"key_up_order": "insensitive"
},
"modifiers": { "optional": ["any"] }
},
"to_if_held_down": [
{ "set_variable": { "name": "cleaning_mode", "value": 0 } },
{ "shell_command": "osascript -e 'display notification \"Cleaning mode OFF\" with title \"Karabiner\" sound name \"Glass\"'" }
],
"parameters": {
"basic.to_if_held_down_threshold_milliseconds": 3000
},
"conditions": [
{ "type": "variable_if", "name": "cleaning_mode", "value": 1 }
]
},
{
"type": "basic",
"from": {
"any": "key_code",
"modifiers": { "optional": ["any"] }
},
"to": [],
"conditions": [
{ "type": "variable_if", "name": "cleaning_mode", "value": 1 }
]
},
{
"type": "basic",
"from": {
"any": "consumer_key_code",
"modifiers": { "optional": ["any"] }
},
"to": [],
"conditions": [
{ "type": "variable_if", "name": "cleaning_mode", "value": 1 }
]
},
{
"type": "basic",
"from": {
"any": "apple_vendor_top_case_key_code",
"modifiers": { "optional": ["any"] }
},
"to": [],
"conditions": [
{ "type": "variable_if", "name": "cleaning_mode", "value": 1 }
]
},
{
"type": "basic",
"from": {
"any": "apple_vendor_keyboard_key_code",
"modifiers": { "optional": ["any"] }
},
"to": [],
"conditions": [
{ "type": "variable_if", "name": "cleaning_mode", "value": 1 }
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment