Is there a way to disable a laptop's internal keyboard?

You can use xinput to float the input device under X.

  1. Execute the command xinput list to list your input devices.
  2. Locate AT Translated Set 2 keyboard and take note of its id number; this will be used to disable the keyboard. Also, take note of the number at the end, [slave keyboard (#)]; this is the id number of the master, which will be used to re-enable your keyboard.
  3. 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.
  4. To re-enable the keyboard, execute the command xinput reattach <id#> <master#>, where master is that second number we noted down. So if the number was 3, you would do xinput reattach 10 3.

Here's a demonstration:

$ xinput list
⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ SynPS/2 Synaptics TouchPad                id=11   [slave  pointer  (2)]
⎜   ↳ Logitech USB-PS/2 Optical Mouse           id=12   [slave  pointer  (2)]
⎜   ↳ Logitech Unifying Device. Wireless PID:4004   id=13   [slave  pointer  (2)]
⎣ Virtual core keyboard                     id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Power Button                              id=6    [slave  keyboard (3)]
    ↳ Video Bus                                 id=7    [slave  keyboard (3)]
    ↳ Sleep Button                              id=8    [slave  keyboard (3)]
    ↳ Acer CrystalEye webcam                    id=9    [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=10   [slave  keyboard (3)]
$ xinput float 10
$ xinput list
⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ SynPS/2 Synaptics TouchPad                id=11   [slave  pointer  (2)]
⎜   ↳ Logitech USB-PS/2 Optical Mouse           id=12   [slave  pointer  (2)]
⎜   ↳ Logitech Unifying Device. Wireless PID:4004   id=13   [slave  pointer  (2)]
⎣ Virtual core keyboard                     id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Power Button                              id=6    [slave  keyboard (3)]
    ↳ Video Bus                                 id=7    [slave  keyboard (3)]
    ↳ Sleep Button                              id=8    [slave  keyboard (3)]
    ↳ Acer CrystalEye webcam                    id=9    [slave  keyboard (3)]
∼ AT Translated Set 2 keyboard              id=10   [floating slave]
$ xinput reattach 10 3
$ xinput list
⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ SynPS/2 Synaptics TouchPad                id=11   [slave  pointer  (2)]
⎜   ↳ Logitech USB-PS/2 Optical Mouse           id=12   [slave  pointer  (2)]
⎜   ↳ Logitech Unifying Device. Wireless PID:4004   id=13   [slave  pointer  (2)]
⎣ Virtual core keyboard                     id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Power Button                              id=6    [slave  keyboard (3)]
    ↳ Video Bus                                 id=7    [slave  keyboard (3)]
    ↳ Sleep Button                              id=8    [slave  keyboard (3)]
    ↳ Acer CrystalEye webcam                    id=9    [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=10   [slave  keyboard (3)]

Here is a little switch button to enable and disable a specific keyboard. First, you have to find your keyboard id with xinput or xinput-list.

Bash script to enable/disable keyboard

#!/bin/bash
Icon="/PATH/TO/ICON_ON"
Icoff="/PATH_TO_ICON_OFF"
fconfig=".keyboard" 
id=12

if [ ! -f $fconfig ];
    then
        echo "Creating config file"
        echo "enabled" > $fconfig
        var="enabled"
    else
        read -r var< $fconfig
        echo "keyboard is : $var"
fi

if [ $var = "disabled" ];
    then
        notify-send -i $Icon "Enabling keyboard..." \ "ON - Keyboard connected !";
        echo "enable keyboard..."
        xinput enable $id
        echo "enabled" > $fconfig
    elif [ $var = "enabled" ]; then
        notify-send -i $Icoff "Disabling Keyboard" \ "OFF - Keyboard disconnected";
        echo "disable keyboard"
        xinput disable $id
        echo 'disabled' > $fconfig
fi

Configuration

  • Icon as the path of icon to display when enabling (for instance, /home/user/path/icon.png)
  • Icoff as the path of the icon to display when disabling
  • I used the following icons : enter image description here enter image description here

  • id as the keyboard id (found it with xinput)

  • fconfig path to config file. Change if you want to create configuration file in another directory

Don't try to run the script if you can't run it again without the use of your keyboard (unless you got another keyboard of course). Create the following launcher (in home/user/.local/share/applications) and add it to unity :

Desktop entry (Unity launcher)

[Desktop Entry]
Version=1.0
Type=Application
Name=Clavier ON-OFF
Icon=PATH/TO/YOUR/ICON
Exec=bash NAME_OF_YOUR_SCRIPT.sh
Path=PATH/TO/YOUR/SCRIPT
NoDisplay=false
Categories=Utility;
StartupNotify=false
Terminal=false

RESULT :

Launcher:

enter image description here

Notifications:

enter image description here enter image description here


Device id's received from xinput list as suggested in accepted answer are sometimes somehow changed on reboot (at least on my PC) which resulted in disabling wrong device.

That's why I've ended using device name instead of id, e.g.:

xinput disable "AT Translated Set 2 keyboard"

I thought of 2 ways you can do this:

  1. By setting up a wrong model for your laptop keyboard in xorg.conf ?

  2. By installing Lock-keyboard-for-Baby

`Lock-keyboard-for-Baby or lk4b in short, is a small program which locks your keyboard but leaves your mouse free. I wrote it because my niece likes to bash away at my keyboard whenever she sees me sit down at it. Keys typed on a keyboard can have disastrous consequences and I didn't want to lock my screen all the time with a screensaver.

When started, lock-keyboard-for-baby opens a small window which grabs the keyboard and echos keys which are typed. By default, it tells you what to type to quit ("Quit Now").

Unlike a screensaver, your screen is not blocked and the mouse still partially works, so you can still see what is on your screen - keep watching tv / video and/or read a document using the mouse to scroll.`

Requirements:

· GTK >= 2.x · perl GTK2 bindings (perl-gtk2 or gtk2-perl depending on your system)


For Disabling Laptop's internal keyboard permanently On Ubuntu, Need pass this i8042.nokbd Kernel parameters for not to check/create keyboard port

i8042.nokbd [HW] Don't check/create keyboard port

Open terminal and run the following command

$sudo gedit /etc/default/grub

Try to find the following line

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

Add parameter i8042.nokbd, the above line should be looks like this

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash i8042.nokbd"

Update grub as following command

$sudo update-grub     

Then reboot your laptop computer.