137

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?

225

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
  • 71
    of all commands... – PNDA Jul 29 '17 at 11:07
  • 82
    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 Jul 29 '17 at 11:46
  • 95
    Bourne's cat isn't mentioned much. It's still too upsetting for everyone concerned. Brian Kernighan's pet awk ate him. – cas Jul 29 '17 at 12:17
  • 18
    Cats make great Perl programmers. Even if it looks like @#${} to you, it probably does something useful. – AlwaysLearning Jul 30 '17 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 Jul 30 '17 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).

  • My keyboard has no "Super" key. – Paŭlo Ebermann Jul 30 '17 at 0:51
  • 10
    @PaŭloEbermann It's the Windows/Command key. – Someone Somewhere Jul 30 '17 at 2:25
  • Doesn't work here. (I'm using an Ubuntu with Xfce, might be related to that.) – Paŭlo Ebermann Jul 30 '17 at 7:27
  • 15
    @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. – Patrick Trentin Jul 30 '17 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! – Thorbjørn Ravn Andersen Jul 31 '17 at 12:12
50

Open vim

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

  • Perhaps a "tortoiseshell" coloured cat might work it out. – Wossname Aug 2 '17 at 13:28
  • 19
    +1 This solution also works to keep most people from using your computer too! – Ogre Psalm33 Aug 2 '17 at 14:28
  • 7
    And then someday Stackoverflow will help one million cats exit VIM.... – jamesdlin Aug 3 '17 at 18:25
  • Pointless. Cats use Emacs. – Peter Flynn Aug 31 '17 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.

  • 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 Jul 30 '17 at 15:02
  • 22
    @cas oh no, i've been found out! – cat Jul 31 '17 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. – unperson325680 Aug 2 '17 at 7:18
  • @MattiVirkkunen is it better now? – Patrick Trentin Aug 9 '17 at 13:03
  • @PatrickTrentin A bit, yes – Matti Virkkunen Aug 11 '17 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.

  • 24
    Presumably the wireless devices need batteries, so the power switch is a handy feature to help preserve battery life. – Digital Trauma Jul 29 '17 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 Jul 31 '17 at 6:44
17

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

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.

  • 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. – Ralph Bolton Jul 31 '17 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 Aug 1 '17 at 3:03
11

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.

  • Yay memories! :D – Dewi Morgan Aug 1 '17 at 16:30
  • oh my god is this real – chris Aug 7 '17 at 11:31
  • I never bought a copy but my understanding is that it is in fact a Real Thing. – studog Aug 16 '17 at 5:00
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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.