Keyboard set to "cat mode"

I am a cat-owner and a cat-lover. But I don’t like it when my cat sits on my keyboard and pushes randoms keys and messes everything up.

I have an idea to have a function key that turns off the keyboard (except for one special key combination). I know there is already CtlS, but this freezes the keyboard and keeps track of the input until the keyboard is unlocked.

Is there any way have the keyboard disregard all input except one hard-to-press-accidentally key combination?

Bonus points: Is there any way to do the same thing in Windows?

Asked By: psitae

||

Open a tiny terminal window somewhere on the screen and run cat in it.

Whenever you want to protect the system from your cat, change focus to that window.

Not many people know this but this feature was an important design goal for the cat program :). Unfortunately, really clever cats (like my evil beast) know what Ctrl-C is.

If your cat is clever enough to figure out Ctrl-C, Ctrl-D, Ctrl- or Ctrl-Z, run cat using this sh script wrapper (/usr/local/bin/toodamnsmartcat.sh):

#!/bin/sh

trap "" TSTP INT QUIT
stty raw -echo

while true; do
  cat -v
done
Answered By: cas

Lock your computer.

It’s a feature you probably already know how to use and it’s super effective.
One can easily activate it with Super-L on most linux systems including the common Debian variants.

Ctrl-Alt-L on Ubuntu.

Windows-L on Windows.

Control-Shift-Eject or Control-Shift-Power on OS X.

All input (except a special unique combination) is blocked and thus provides effective cat-blocking.

It’s available on most computer systems (including Microsoft Windows).

Answered By: BlueWizard

Another option is to acquire a keyboard and/or mouse with a power switch. This is more common for some bizarre reason on wireless devices. I’m more worried about the toddlers in my house than the cats, but “It must have a physical power switch” is on my list of requirements when purchasing an input device.

Answered By: user228716

SHORT ANSWER:

type CTRL+ALT+F2 when AFK, and CTRL+ALT+F7` when coming back.


LONG ANSWER:

Although I upvoted the solution proposed by @cas, I think that opening a cat terminal has a few disadvantages:

  • when the sloppy mouse option is enabled, it suffices that the cat pushes the mouse outside of the window area of the terminal to redirect the input to application in the background (or the desktop). As a result, the cat command becomes useless because it is no longer receiving any input.
  • some unix/linux installations come with super easy key bindings which switch the foreground application receiving the input coming from the keyboard, again rendering the cat command useless; e.g. on my system, the SUPER key opens the application menu.

Opening a vim terminal as @DanJab suggested is subject to the same issues of using a terminal with cat.

Locking the session as suggested by @BlueWizard has the disadvantage that one has to type again his/her own password. This is clearly a sensible approach when leaving the computer unattended in public spaces for a long time, but it’s a bit of an overkill for short breaks at home, especially when the login password is both long and complex to type.

Thus, my proposed solution is to use the combination

CTRL+ALT+F2

so as to temporarily switch the system to a login terminal. Unless the cat figures out your own login and password or, against all possible odds, inadvertently presses CTRL+ALT+F7, your session should be completely safe.

This works on any Linux system that I have tried, requires no extra configuration/script, it’s very fast to use and easy to remember.

Answered By: Patrick Trentin

If you’re not using a laptop, you could use a hardware solution by unplugging the keyboard. If that’s too inconvenient, you could get a USB hub with physical switches and plug your keyboard into that. Possibly keep the hub away from the keyboard. Then you can disconnect/reconnect your keyboard by pressing a switch on the hub.

Answered By: jamesdlin

For the bonus points:

I can’t believe

  1. Pawsense is still around
  2. Nobody’s mentioned it yet

They don’t appear to have ported it to *nix though.

Answered By: studog

My keyboard already has this feature. It’s called OFF ON and it has a tiny switch in it. If a cat can flick that switch I’d be very impressed!

OFF ON keyboard switch

Answered By: CJ Dennis

Open vim

Even the most intelligent cat will not be able to exit vim.

Answered By: LexBailey

You might want to consider getting something like this mainly because it also lessens the amount of cat hair that ends up in your keyboard. You do have to spend some money but as added bonuses you don’t need to press a key combination, start an app or keep an app running, it works on any OS, and you can still use your keyboard while your cat is there.

Also I wanted comment on the suggestion to open vim, but apparently I do not have enough reputation to do so yet. Sadly, Ctrl and Z is too close to each other making it easy enough for a cat to put vim in background and getting immediate access to the shell.

Answered By: jaybz

If you’re using your computer while your cat is on the keyboard (if you f.i. watch a video / read a PDF or website), the proposed solutions are impractical, as they open and focus another window / TTY which may hide the window you would like to see.

Another simple solution is to temporarily remap almost all keys of your keyboard, except for those used in a key combination that is used to reactivate the normal keyboard, and disable the trackpad via xinput. With the configuration described below, you

  • Disable keyboard & mouse: Mod4 + shift + c
  • Re-enable keyboard & mouse Mod4 + shift + esc

In the i3-wm, this can be achieved by adding the mappings

# Disable keyboard
bindsym Mod4+shift+c exec "xinput disable 12 && xinput disable 13 && xmodmap ~/.xmodmapDisable"
# Enable keyboard:
bindcode Mod4+shift+9 exec "setxkbmap -layout us; xinput enable 12 && xinput enable 13"

to the .config/i3/config. This can be also used for other window managers, though the syntax for binding the keyboard combination will be different. Also my xinput ids, key codes and the keyboard layout might have to be replaced as explained below.

Command 1. Disable keys & mouse:
The xinput ids represent the trackpad and trackpoint at my machine, the ids for other machines can be found out by inspecting the output of xinput.
The .XmodmapDisable file disables most all keys except for mod, shift and escape in my example configuration. Keycode 9 for escape might be different for your keyboard. You can find out the keycodes by typing xev and the keys in questions, and enable them in the file you load via xmodmap.

Command 2. Re-enable keyboard + mouse: You might have to change the keyboard layout in the command above from us to whatever you are using.

Disadvantages of this approach:

  • at my keyboard one of the function keys still operates when the keys are remapped, such that I go offline from time to time if my cat presses the disconnect-wifi key.
  • As the excape key is part of my mapping to re-activate the keyboard, it can also be used by the cat.
  • as xinput and xmodmap are used, this is only usable for implementations of X; if you’re using a Wayland implementation though, there might be a replacement; if you are on a TTY, cat does the trick.
Answered By: mutableVoid
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.