Split keyboard on top of a laptop on a lap, sat in a train, with various bags and suitcases in the background

Do you also find yourself wanting to use your custom keyboard while travelling with your Linux laptop? Without triggering keypresses through the built-in keyboard underneath of course!

I’ll first show you how to disable the built-in laptop keyboard with a bash script. And then automatically disable the laptop keyboard when, and only when, your custom keyboard is plugged in, and enable it again when your custom keyboard is unplugged.

How to disable the built-in keyboard

You can disable the keyboard dynamically by writing 1 to the inhibited property in sys/devices/.../input/input3. Enabling is a matter of writing 0 to the same path.

First we need to find the precise SysFs path of the internal keyboard:

cat /proc/bus/input/devices | less

If necessary, type / then keyboard to search the output.

[...]
N: Name="AT Translated Set 2 keyboard"
P: Phys=isa0060/serio0/input0
S: Sysfs=/devices/platform/i8042/serio0/input/input3
[...]

Fill in the SYSFS_PATH in the following script, which I save to /home/freek/Scripts/laptop-kb.sh (and make it executable with chmod +x <filepath>):

#!/usr/bin/env bash

SYSFS_PATH=/devices/platform/i8042/serio0/input/input3
DEV_PATH="/sys/${SYSFS_PATH}/inhibited"

case "$1" in
    disable)
        echo 1 | sudo tee "$DEV_PATH"
        ;;
    enable)
        echo 0 | sudo tee "$DEV_PATH"
        ;;
    toggle)
        cur=$(cat "$DEV_PATH")
        new="1"
        if [ "$cur" = "1" ]; then $new="0"; fi
        echo $new | sudo tee "$DEV_PATH"
        ;;
    *)
        echo "Usage: $0 {enable|disable|toggle}" >&2
        exit 1
        ;;
esac

Trigger on plug / unplug external keyboard

To only disable it when a specific external keyboard is plugged in, write a udev rule that will trigger different actions on plug and unplug of the external keyboard. udev is part of systemd and included in most modern Linux distributions, including Arch Linux, by default.

First find the external keyboard’s PRODUCT id by watching the output of this command:

sudo udevadm monitor --kernel --property --subsystem-match=usb

While plugging and unplugging the external keyboard.

For my keyboard, it is: PRODUCT=a8f8/1836/200

Then write a udev rules file with the following rules. Replace your PRODUCT id and script path and save this to /etc/udev/rules.d/99-disable-internal-keyboard.rules

SUBSYSTEM=="usb", ACTION=="add", ENV{DEVTYPE}=="usb_device", ENV{PRODUCT}=="a8f8/1836/200", RUN+="/home/freek/Scripts/laptop-kb.sh disable"
SUBSYSTEM=="usb", ACTION=="remove", ENV{DEVTYPE}=="usb_device", ENV{PRODUCT}=="a8f8/1836/200", RUN+="/home/freek/Scripts/laptop-kb.sh enable"

Then reload the udev rules by rebooting or run: udevadm control --reload-rules && udevadm trigger

Have fun working on your Linux laptop anywhere with your custom keyboard!


Thanks to Koen Vervloesem for figuring this stuff out for webcams.