Last active
March 5, 2026 08:07
-
-
Save Nightblade/ed67e942386834d3c75362124851e4ea to your computer and use it in GitHub Desktop.
Block keyboard input so you can clean it while it's plugged in.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| KeyboardClean.ahk | |
| ------------------ | |
| Temporarily disables keyboard input to allow cleaning while plugged in. | |
| NOTE: Must be Run as Administrator to be 100% effective. | |
| Version History: | |
| v2.3 - 2026-02-24 Add note about Run as Administrator; misc AHK2 tweaking | |
| v2.2 - 2025-02-24 (Re-enable keyboard on exit as a precaution) | |
| v2.1 - 2025-02-22 (Merged enable/disable functions into a toggle) | |
| v2.0 - 2025-01-14 | |
| v1.0 - 2025-01-02 | |
| */ | |
| #Requires AutoHotkey v2 | |
| #Warn | |
| #SingleInstance Force | |
| InstallKeybdHook | |
| AppName := "Keyboard Cleaner" | |
| AppVersion := "2.3" | |
| KeyboardEnabled := True | |
| GuiWindow := Gui("+AlwaysOnTop -MinimizeBox -MaximizeBox -SysMenu -Resize", AppName . " " . AppVersion) | |
| ToggleButton := GuiWindow.Add("Button", "y+10", "Disable Keyboard") | |
| ToggleButton.OnEvent("Click", ToggleKeyboard) | |
| GuiWindow.Add("Button", "x+10", "Quit").OnEvent("Click", QuitApp) | |
| GuiWindow.Show() | |
| ToggleKeyboard(*) { | |
| Global KeyboardEnabled := !KeyboardEnabled | |
| Loop 512 { | |
| Hotkey(Format("SC{:X}", A_Index), KeyboardEnabled ? "Off" : DoNothing, "On") | |
| } | |
| ; Update button text to show what clicking it will do | |
| ToggleButton.Text := KeyboardEnabled ? "Disable Keyboard" : "Enable Keyboard" | |
| } | |
| ; Enable keyboard on app exit as a precaution | |
| QuitApp(*) { | |
| if NOT KeyboardEnabled { | |
| ToggleKeyboard() | |
| } | |
| ExitApp | |
| } | |
| ; Dummy function that does nothing | |
| DoNothing(*) { | |
| Return | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment