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?

Cadoiz
  • 276
psitae
  • 1,481

10 Answers10

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
cas
  • 78,579
  • 73
    of all commands... – Aloha Jul 29 '17 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 Jul 29 '17 at 11:46
  • 7
    I cannot, for the life of me, find any info about S. Bourne's cat. Instead, the best info I can find is that it's shorthand for "catenate", which is another term for "concatenate". I still want to learn about his cat though. – Aloha Jul 29 '17 at 11:56
  • 96
    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
  • +1 My keyboard doesn't have n-key rollover, so when the cat is on it mashing multiple keys, the mouse is the only way to send input. – Mark Plotnick Jul 29 '17 at 13:13
  • 13
    True pet command name etymology: https://en.wikipedia.org/wiki/Biff – Mark Plotnick Jul 29 '17 at 13:16
  • 2
    I tried this, and I noticed that Ctrl-Z is quite easy to push by accident (even with a dvorak keyboard). Is there anything more robust against random pushing of keys? – psitae Jul 29 '17 at 14:05
  • 4
    Instead of a terminal, how about xev >/dev/null &? No possible keyboard input to the window it displays will make it quit. (Note: window manager hotkeys not covered by guarantee). – hmakholm left over Monica Jul 29 '17 at 14:28
  • 3
    I can't upvote this as it woudn't stop my cat from messing things up, she would just use the mouse. – ian Jul 29 '17 at 17:58
  • 18
    Cats make great Perl programmers. Even if it looks like @#${} to you, it probably does something useful. – AlwaysLearning Jul 30 '17 at 01: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
  • 2
    @psitae, German keyboard are ctrl-Z protected. – Carsten S Jul 30 '17 at 19:10
  • 13
    This explains so many commands... To withstand bison, a keyboard must flex. – Eliah Kagan Jul 30 '17 at 22:11
  • 3
    What if it learns Ctrl+D? – Stéphane Chazelas Jul 31 '17 at 10:20
  • 3
    Also stty raw -echo; cat -A (with some cats) to prevent special key processing and still see what your cat typed (and keep the cat command). – Stéphane Chazelas Jul 31 '17 at 13:59
  • 2
    Great anecdote!  Seriously, though, the cat command was in Unix from day 1, and I believe that Stephen Bourne didn’t join the team until later.  “Ken’s cat” is more plausible, and (IMO) sounds better, too.  (And I assume that you know the real story of where the grep name came from.) – Scott - Слава Україні Jul 31 '17 at 20:01
  • I can not reveal my sources :-). and yep. g/re/p from ed (still useful for scripted edits) – cas Aug 01 '17 at 01:39
  • 7
    Oh my god, is this why it's so hard to exit vim? That's just... the world is so different now. – candied_orange Aug 01 '17 at 03:31
  • 1
    This is cute and clever, but not a real solution to the problem. Locking the screen is really the right answer, I think – Josh Aug 02 '17 at 16:10
  • If you knew someone who did this, you would be obliged to type in a LOLCAT message in the terminal. CAN HAS CHEEZBURGER? – dan-gph Aug 07 '17 at 02:21
  • 1
    Run tomcat - this will make the computer so slow that nothing bad can happen before you are back :) – rackandboneman Aug 07 '17 at 09:38
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).

Freiheit
  • 9,669
  • My keyboard has no "Super" key. – Paŭlo Ebermann Jul 30 '17 at 00:51
  • 12
    @PaŭloEbermann It's the Windows/Command key. – SomeoneSomewhereSupportsMonica Jul 30 '17 at 02:25
  • Doesn't work here. (I'm using an Ubuntu with Xfce, might be related to that.) – Paŭlo Ebermann Jul 30 '17 at 07: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. – Patrick Trentin Jul 30 '17 at 11:56
  • Super+L worked for me on Unity as well, and Super is equivalent to the Windows key so basically everything allows Super+L, most also allow Ctrl+Alt+L – somebody Jul 31 '17 at 01:48
  • 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
  • Crtl+Alt combinations are traditionally used for system shortcuts on X11. Ctrl+Alt+Backspace terminates the X server, Ctrl+Alt+F1,F2,… switch to another console. Ctrl+Alt+Del and Ctrl+Alt+Esc are usual system shortcuts too. Does IntelliJ really use Ctrl+Alt combinations? – cg909 Jul 31 '17 at 20:51
  • @cg909 It does have some, though those all are configurable. IntelliJ has a shitload of keyboard shortcuts for each and every action, so it couldn't have missed it. Here's a much more annoying problem: having insert and print screen on the same key and a F-lock key, so you have to choose between Insert and F* keys (or hope your DE hasn't kidnapped the printscreen key so programs can actually detect it) – Luke Jul 31 '17 at 23:05
  • I'd go a step further and use something like BluePromity to automatically lock the desktop when you walk away just in case you forget to lock it manually. You can set a low timeout to minimize the time the cat has to hop up and start asking the internet for Cheezbugers. – Johnny Aug 01 '17 at 16:09
  • Lock combination can be reconfigured, if you do not have required keys. Also, for both KDE and Unity, Ctrl+Alt+L works by default – TimSparrow Aug 02 '17 at 10:16
53

Open vim

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

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.

Cadoiz
  • 276
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 06: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

CJ Dennis
  • 281
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.

phuclv
  • 2,086
studog
  • 527
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.

jamesdlin
  • 838
  • 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 01 '17 at 03: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.

jaybz
  • 21
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.