How to disable and enable keyboard in ubuntu?

To Disable/Enable the keyboard, just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command(s) below:

xinput -list

enter image description here

Once you find your ID, then

sleep 0.1 ; xinput set-prop 9 'Device Enabled' 0 ; sleep 5 ; xinput set-prop 9 'Device Enabled' 1

sleep 5 is the number of seconds (I guess) you want the keyboard to be disabled.

For more information on the xinput command see the ManPage.

Or you can use Lock keyboard utility.


Run xinput -list and find the id for AT Translated Set 2 keyboard as mentioned in the accepted answer. You may need to install xinput first.

I created the following script, and I run this via a Launcher I can click on with my mouse. Each time you click it, it toggles on or off the keyboard. Replace 13 with the ID number of your keyboard.

#!/bin/bash

if [[ $(<~/.keyboard-status) == "enabled" ]]; then
    xinput --disable 13
    echo "disabled" > ~/.keyboard-status
else
    xinput --enable 13
    echo "enabled" > ~/.keyboard-status
fi

To automate both enabling and disabling Internal keyboard of laptop from cmdline, a shell script was written for my personal use at https://github.com/anitaggu/ikbdop.

A brief youtube tutorial is also available here at https://youtu.be/LvoIwqFutlg