How do I disable all the keys of the keyboard except for three?

So I want to disable all the keys on my keyboard except for ‘ctrl’, ‘alt’, and ‘E’. How do I do this with the help of a command that I can bind to a keyboard shortcut.
I figured out how to disable the entire keyboard using the following command xinput float 17.

Thanks

Asked By: Akshay Alva

||

Try xmodmap:

xmodmap – utility for modifying keymaps and pointer button mappings in X

  1. Use xmodmap -pke to find out which keys have which keycode on your keyboard.
  2. Disable a key by using xmodmap -e 'keycode 24 = 0x0000' replacing 24 with the respective keycode of the key which you want to disable.
  3. Repeat step 2 for all listed keycodes to disable all keys. You can for example use a for loop to do so quickly:
#!/bin/bash
 
for i in {8..255}
do
    echo "Disabling keycode $i ..."
    xmodmap -e "keycode $i = 0x0000"
done
Answered By: Ishidres
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.