138

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 Ctl-S, 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?

14
  • 25
    super+L ? :-p. You might also be amused to search "cat-like typing detected".
    – sourcejedi
    Commented Jul 29, 2017 at 7:45
  • 18
    ctrl-s freezes output, not input. Commented Jul 29, 2017 at 8:25
  • 16
    How to protect a keyboard from a cat?
    – cas
    Commented Jul 29, 2017 at 8:50
  • 47
    Please note that cats have no problem entering key combinations that are designed to be hard to press accidentally, such as Alt+SysRq+C.
    – CL.
    Commented Jul 30, 2017 at 8:38
  • 24
    Get a CRT to replace your LCD! It is warm so the cat sleeps on top. Commented Jul 31, 2017 at 12:13

10 Answers 10

228

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
21
  • 73
    of all commands...
    – Aloha
    Commented Jul 29, 2017 at 11:07
  • 83
    yes, well, this was cat's original purpose - to prevent Stephen Bourne's cat from messing with the first unix systems. the fact that it could also output the content of files was just a side-effect, a happy accidental discovery. and grep was actually named after Dennis Ritchie's cat. :-p
    – cas
    Commented Jul 29, 2017 at 11:46
  • 96
    Bourne's cat isn't mentioned much. It's still too upsetting for everyone concerned. Brian Kernighan's pet awk ate him.
    – cas
    Commented Jul 29, 2017 at 12:17
  • 18
    Cats make great Perl programmers. Even if it looks like @#${} to you, it probably does something useful. Commented Jul 30, 2017 at 1:16
  • 19
    @KingZoingo in which case they would make great bad Perl programmers. This annoying idea that Perl is ilegible only comes from the simple fact that Perl doesn't force you to write clean code. It absolutely doesn't stop you from doing so and even makes it easy to do so. It's just that most programmers are lazy and write crappy code and yes, crappy code in Perl can look like a cat was walking on your keyboard. (Sorry Perl person here and I'm fed up with people thinking all the bad Perl they've seen is what Perl actually is).
    – terdon
    Commented Jul 30, 2017 at 18:00
72

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).

10
  • My keyboard has no "Super" key. Commented Jul 30, 2017 at 0:51
  • 12
    @PaŭloEbermann It's the Windows/Command key. Commented Jul 30, 2017 at 2:25
  • Doesn't work here. (I'm using an Ubuntu with Xfce, might be related to that.) Commented Jul 30, 2017 at 7:27
  • 16
    @PaŭloEbermann different OSs/DEs have different key bindings. That i know, SUPER+L works on Fedora/Gnome, CTRL+ALT+L on Ubuntu/Unity. Try check in your settings what is the shortcut for locking the desktop/session. Commented Jul 30, 2017 at 11:56
  • 8
    Whoever misguided system architect that decided to steal Ctrl-Alt combinations in Ubuntu should be forced to work with a modern IDE like IntelliJ without being able to change shortcuts until they see WHY this is a bad idea. And then some. And a few millenia! Commented Jul 31, 2017 at 12:12
53

Open vim

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

4
  • Perhaps a "tortoiseshell" coloured cat might work it out.
    – user155838
    Commented Aug 2, 2017 at 13:28
  • 21
    +1 This solution also works to keep most people from using your computer too! Commented Aug 2, 2017 at 14:28
  • 7
    And then someday Stackoverflow will help one million cats exit VIM....
    – jamesdlin
    Commented Aug 3, 2017 at 18:25
  • Pointless. Cats use Emacs. Commented Aug 31, 2017 at 12:50
37

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.

5
  • 45
    you realise, don't you, that half the reason your cat is in your lap is so they can watch you type your password?
    – cas
    Commented Jul 30, 2017 at 15:02
  • 22
    @cas oh no, i've been found out!
    – cat
    Commented Jul 31, 2017 at 4:03
  • In some setups when you are outside X, you can use left and right Win keys to switch to left/right VT instead of going C-A-F# ... thus Cat might get around the VT if lucky.
    – mike3996
    Commented Aug 2, 2017 at 7:18
  • @MattiVirkkunen is it better now? Commented Aug 9, 2017 at 13:03
  • @PatrickTrentin A bit, yes Commented Aug 11, 2017 at 14:18
20

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.

2
  • 24
    Presumably the wireless devices need batteries, so the power switch is a handy feature to help preserve battery life. Commented Jul 29, 2017 at 23:37
  • 6
    Keyboards may usually not have power switches but a lot of them do have socketed USB cables which would be trivial to unplug when leaving a computer unattended.
    – Coxy
    Commented Jul 31, 2017 at 6:44
18

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

12

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.

3
  • Yay memories! :D Commented Aug 1, 2017 at 16:30
  • oh my god is this real
    – chris
    Commented Aug 7, 2017 at 11:31
  • I never bought a copy but my understanding is that it is in fact a Real Thing.
    – studog
    Commented Aug 16, 2017 at 5:00
11

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.

2
  • 5
    Use a monitor with a USB hub in it - mine turns off the hub when the monitor is off - so it's trivial to turn off all USB connected devices with a single (fairly convenient) switch. Commented Jul 31, 2017 at 10:56
  • 1
    Just in case anyone's considering @RalphBolton's suggestion -- there are plenty of monitors which do not turn the hub off (and some unfortunate ones just cease to power the hub, meaning low-powered devices like keyboards will still work while others will not), so I'd check before investing in a whole new monitor just to solve this problem ;-)
    – A C
    Commented Aug 1, 2017 at 3:03
2

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.

1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .