zaro

How Do I Disable Keyboard Input in Linux?

Published in Linux Input Devices 3 mins read

To disable keyboard input in Linux, you typically use the xinput command, which allows you to manage input devices in the X Window System (common in most desktop Linux environments). This method detaches the keyboard from its master device, making it inactive.

Understanding xinput

xinput is a utility that queries and configures X input devices. Each input device (like your keyboard, mouse, touchpad) has an associated ID number and is usually attached to a "master" device. Disabling a keyboard via xinput often means detaching it from its master, a process referred to as "floating" the device.

Step-by-Step Guide

Follow these steps to disable and re-enable your keyboard using xinput.

1. Find Your Keyboard's ID

First, you need to identify your keyboard's specific ID number.

  • Open a terminal window.
  • Execute the command xinput list.
  • Look for your keyboard in the list. It will likely have "keyboard" in its description. Note the number next to it.
xinput list

Example Output Snippet:

⎡ Virtual core pointer                      id=2  [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4  [slave  pointer  (2)]
⎜   ↳ SYNA7509:00 06CB:CD41 Touchpad          id=12 [slave  pointer  (2)]
⎣ Virtual core keyboard                     id=3  [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5  [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=10 [slave  keyboard (3)]
    ↳ USB Keyboard                              id=11 [slave  keyboard (3)]

In this example, you might have an AT Translated Set 2 keyboard with ID 10 or a USB Keyboard with ID 11. You'll also see a master keyboard device, typically ID 3 in this example. The number in parentheses (3) next to the slave devices (like IDs 10 and 11) indicates which master device they are attached to (Master Keyboard with ID 3). Remember this master ID for re-enabling.

2. Disable the Keyboard

Once you have the keyboard's ID, you can disable it.

  • Use the xinput float command followed by the ID number.
xinput float <id#>
  • As per the reference: To disable the keyboard, execute the command xinput float <id#> , where <id#> is your keyboard's id number. For example, if the id was 10 , then the command would be xinput float 10 .

  • Example: If your keyboard's ID is 10, the command is:

xinput float 10

After executing this command, your keyboard should stop sending input to applications. Note that this typically only affects the graphical environment (X server) and might not prevent input in a virtual console (TTY).

3. Re-enable the Keyboard

To re-enable the keyboard, you need to reattach it to its original master device. You will need the keyboard's ID (<id#>) and the master keyboard's ID (<master#>, which was usually 3 in the example xinput list output).

  • Use the xinput reattach command followed by the keyboard ID and the master keyboard ID.
xinput reattach <id#> <master#>
  • As per the reference: To re-enable the keyboard, execute the command xinput reattach <id#> <master#> , where master is that second number we noted down. (The reference means the master ID the device was attached to, which was the number in parentheses like (3) in the xinput list output, corresponding to the master keyboard device ID).

  • Example: If your keyboard ID is 10 and the master keyboard ID is 3, the command is:

xinput reattach 10 3

Your keyboard should now be functional again.

Command Summary

Here's a quick summary of the commands:

Action Command Syntax Example (using ID 10, Master 3)
Find ID/Info xinput list xinput list
Disable xinput float <id#> xinput float 10
Re-enable xinput reattach <id#> <master#> xinput reattach 10 3

Important Note: Disabling the keyboard this way is usually temporary and lasts until the X server is restarted or you manually reattach it. Closing the terminal window where you ran the command does not automatically re-enable the keyboard.