Disable a Keyboard or Touchpad in Linux via Command Line

12:48 PM

Let's face it. Laptop keyboards (and touchpads too!) suck. They quite often offer no spill protection or durability for their users, and when they break down, it can be quite a pain to break the entire laptop down just to disconnect the keyboard and replace it. This is probably why most folks simply plug in an external keyboard and leave the internal built in keyboard as is. However, sometimes you end up with a punk rock keyboard or touchpad that decides it wants to complain about its malfunction by repeatedly typing unwanted characters that won't stop, or that moves the pointer on your screen at random. In my case, after having one of my kids spill a soda on it, my laptop's keyboard wanted to intermittently type an endless line of "b" and the occasional "n" which was driving me absolutely bonkers and rendering my laptop unusable.

If you do a Google search about it, most of the forum replies are telling people that there is no way you can disable a keyboard or touchpad from Linux. This is not true, at all. Pretty much ANY piece of hardware can be disabled in Linux via the command line.

And now you're going to find out how to do it.

Please note, I am taking the simpler route by using X.Org's xinput to do this. If you are running a terminal only environment, you will need to resort to lsmod to disable your internal built in keyboard or touchpad in Linux.

Open up your terminal and type (or copy and paste) the following:

xput list

Press Enter and you'll get a list of connected modules. You'll want to find your internal built in keyboard and/or touchpad in this list, which should be pretty easy to identify since any USB keyboards/mice will be clearly labeled as USB connected. Make note of the ID number listed beside your keyboard or touchpad, as this will be needed to identify it in the next step which will disable it.


Now type (or copy and paste) the following:

xinput set-prop XX "Device Enabled" 0


Replace the XX in that command with the ID number of the keyboard or touchpad you're wanting to disable, which you found out in Step 1. The 0 at the end of the command means the device is disabled. If you want to enable it again in the future, you can use this same command to do so just by replacing that 0 with a 1.

Please note that upon reboot, this command will no longer be in effect. If you would like the changes to remain permanent, you will need to add the command to /etc/rc.d/rc.local so it is applied at boot time.

You Might Also Like

4 comments

  1. Important typo: 'xput list' should be 'xinput list'

    It should be noted that 'xinput' is not installed by default in all distros.

    ReplyDelete
    Replies
    1. Thank you for noting that, W. As far as I am aware, xinput is part of X.Org, which is why I noted it would not work without X.Org.

      Delete
  2. This could be useful as a way to disable/enable a trackpad on a laptop that doesn't have a built in function to do so using the keyboard shortcut of your choice.

    ReplyDelete