How to automatically disable notebook integrated keyboard in Linux

Sometimes you may want to disable the integrated keyboard of your laptop or notebook. For example in the case it's broken and some key result as always pushed.

This is an easy one-line script to disable the internal keyboard. You can execute it in the terminal or put it on a .sh script. This is not the best way, but it worked for me and that's all I need :–) I hope it can work for you, too.

The code

xinput float $(xinput list | grep AT | cut -d'=' -f 2 | cut -c 1-2)

How it works

xinput list allows to see all the attached input devices xinput float allows to virtually detach one of the input devices

Example of the xinput list command result: Virtual core pointer id=2 [master pointer (3)] ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)] ⎜ ↳ MLK Trust Deskset 16593 id=12 [slave pointer (2)] ⎜ ↳ Logitech M570 id=13 [slave pointer (2)]

To detach the Logitech M570 I should input xinput float 13 where 13 is the M570 ID on my system (it's shown by the xinput list command)

Since the integrated keyboard is often shown as “AT Translated Set 2 keyboard”, the code above just extracts the ID number of the “AT Translated Set 2 keyboard”.

The cut -d'=' -f 2 is used to cut only 2 char and it should be enough without the next cut command, but it doesn't work and I can't figure out why. I had use the cut command twice to achieve the result I need.

Important note

This script works if the ID of your integrated keyboard is >9 (it's composed by 2 char and not only 1). If your AT device id is <=9 you should change the cut -c 1-2 to cut -c 1-1

How to run it automatically

This part heavily depends on your distro and dekstop environment. You can run it manually, running the string in the terminal everytime you boot the system, but I think the easy way is to put that string in a executable .sh script. * Just open the notepad app and save it with the .sh extension. * Then run chmod +x NameOfTheScript.sh to make it executable

Now you can run it at the startup: double click on it or put the script in the startup applications. If you need more details, just search online run sh script at startup linux (or specifying your distro or dekstop envinronment) and you will find a lot of guides.