Disable Your Keyboard So You Can Clean It
I use a wired keyboard and I don't like the idea of disconnecting it every time I want to clean it.
We’re going to go over a couple of solutions for different operating systems.
This will range from not needing to install anything to downloading and running free tools depending on your OS.
# Why?!
This is especially handy if you have a wired keyboard or a laptop where you may want to lock or disable your keyboard temporarily to give it a thorough cleaning. You can unplug it physically but I don’t like the idea of routinely unplugging and plugging in devices.
I like to keep my workstation powered on 24 / 7 too.
When you thoroughly wipe your keyboard down you’re probably going to hit a bunch of random keys. These can have unforeseen circumstances if you get unlucky, such as selecting and deleting files.
I’ve accidentally shut down Windows in the past. When I tweeted about this a few years ago someone replied that they sent an unintended email out to someone:
Normally I wipe down my keyboard once a week. When I do this I keep Vim open to capture keystrokes.
— Nick Janetakis (@nickjanetakis) September 18, 2021
Today I decided to live on the edge and did it faster than usual and didn't open anything. Within 3 seconds I ended up shutting down Windows.
Do you have any kb cleaning stories?
Since then I’ve had things happen even with Vim open. For example, any global hotkeys will still trigger and then other apps can take focus.
Needless to say, having your keyboard disabled so you can goto town on your keyboard with a rag once in a while is a good idea.
# No Tools
This should work on all operating systems without any extra tools.
Chances are you have a lock screen such as when you hit Win + L
on Windows.
This will disallow interacting with applications until you enter in your
password. If you have a decent password, the odds of you randomly typing your
password are close to zero.
Honestly, this is a really good option. On Windows there’s only a microscopic chance of shutting down your machine if you happen to TAB over to the power down icon and hit enter or do something similar by hitting CTRL + ALT + DEL randomly.
Technically you can end up turning on scroll, num or caps lock too but that’s easy enough to toggle back off.
You really only need to worry about inputting the wrong password N number of times which may lock you out of your device pending whatever your lock out policies are. Perhaps you’re on a work machine and can’t control this or don’t want to risk it.
I think for a personal machine this is likely good enough but if getting locked out has consequences we can do better.
# Using a Tool
I run Windows so let’s focus on that first. I’ll do my best to offer some suggestions for macOS and Linux but keep in mind I didn’t test those first hand.
Windows
If you’re on Windows, we’re going to cover 2 options focused on AutoHotkey:
- If you have AutoHotkey installed you can use the AHK script directly
- If you don’t have AutoHotkey you can use a pre-compiled executable of that script
The first option is safer because you don’t have to run an executable off the internet. I already have AutoHotkey because I remapped caps lock to escape with it.
I’m going to leave it up to you on which option to choose but you can download a zip file which has both the raw AHK script and icons as well as an executable that was compiled from the AHK script. Please read the disclaimer first.
DISCLAIMER
You can download the zip file here: https://www.howtogeek.com/wp-content/uploads/2017/01/Keyboard-Locker.zip
- I am not the author of this zip file, AHK script or executable
- Do not take it being linked to from my site as a definitive source of safety
- This zip file could be safe today but unsafe tomorrow
- If it becomes a security problem, I will host it on my domain in the future
- The original AutoHotkey forum post to give credit to the user who created it 404s
- The zip file link was taken from this blog post on How to Geek
AHK script vs executable
This is up to you. I took a look at the AHK script and it looks reasonable. I’m not super into AHK scripting but nothing stood out as doing anything malicious. I actually ended up scanning the executable using an online virus scanner and it came up clean.
If you have AHK already installed, I would run the script directly. That’s what I do.
If you don’t have AHK you can run the executable.
Using it
It works the same no matter how you run it.
After it’s running you can hit CTRL + ALT + L
to lock your keyboard. You’ll
see the icon in your system tray turn into the lock icon. If you input keys
they won’t register which is perfect. You can type unlock
for things to go
back to normal.
I personally only keep it running when I use it so I didn’t bother to configure it so it auto-starts on Windows boot. I’ll leave that up to you but I have details on doing that in my other AHK blog post on remapping keys near the bottom of the post.
That’s it, you’re good to go to clean your keyboard!
macOS
I can’t vouch for either of these solutions since I didn’t test them. They are what came up when Googling for solutions.
The first one had quite a few positive references on the internet from folks on Reddit:
The other one seems to be created by a developer on YouTube with 200k+ subscribers:
I have no stake in this but I’d probably choose the first one because it focuses on doing one thing which is locking your keyboard. There could be other solutions too, I didn’t look that hard since it’s tough to recommend something without using it first hand.
Linux
Chances are you’re a power user and I’m sure the lock screen solution is sufficient.
If not, I don’t think I can offer many suggestions without having tried anything because it may depend on your distro and desktop environment.
Google says there’s a bunch of reasonable options around using xinput
to
detect your keyboard device and then you can disable it. Of course then you’d
need to figure out how to re-enable it again without using your keyboard.
You could maybe have it get automatically re-enabled after 3 minutes or perhaps have a second script that you can double click with your mouse to run it which enables your keyboard again.
With that said, I would Google for “Linux lock keyboard for cleaning”. Having the cleaning term in there seems to help find posts focused on this use case.
The video below goes over this post in more detail and demos the AHK solution.
# Demo Video
Timestamps
- 0:24 – Why?
- 2:09 – Using the lock screen
- 4:03 – Using an AHK script with Windows
- 11:08 – Options for macOS
- 13:11 – Options for Linux
Which method did you use to clean your keyboard? Let me know below.