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.
ctrl-s
freezes output, not input.