A week ago, I spilt the contents of my cup onto my laptop keyboard. Half of the keys no longer work, except one! The letter Q which is very active regularly.

This is very disturbing as I work.

Is there a way to disable the internal keyboard of a laptop?

Is it possible with xmodmap?

  • What brand and model laptop is it?
    – Mitch
    Commented Aug 21, 2012 at 21:18
  • it's HP pavilion dv9000
    – atmon3r
    Commented Aug 21, 2012 at 21:31
  • 6
    The most straightforward way would be to lift the keyboard and disconnect it from the motherboard. You can then place it right back down where it was, sans the connection. This way the keyboard will be disabled after reinstalls and you wont need to bother with software. See this link, about halfway down the page where it gets to the keyboard: insidemylaptop.com/… Commented Aug 21, 2012 at 22:00
  • Might also be worth taking it out, taking it apart, an cleaning between the layers.. Commented Mar 1, 2015 at 14:25
  • "a user looks for a software solution, lets provide him/her with a hardware approach" Commented Jun 9, 2021 at 0:23

13 Answers 13


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)]
  • 2
    You would use the reattach argument to reattach it. xinput reattach 14 3 Commented Aug 21, 2012 at 22:25
  • 1
    Perfect answer - was looking for this too. any of the keys on my laptop stopped working so now keep an external keyboard over it and it kept pressing the control key and what not. This fixed it up, thanks! Commented Dec 15, 2012 at 22:08
  • 2
    Thanks. But after restarted my laptop, the keyboard is enabled automatically. So all the time when I on my machine, I want to do the above steps to disabled the internal keyboard that you have mentioned. Is there any possibilities to disabled permanently?
    – Dinesh ML
    Commented Dec 17, 2015 at 6:59
  • 4
    Wouldn't xinput disable/enable do the same thing? Commented Apr 20, 2016 at 23:49
  • 2
    What if you forget the master? xinput list prints [floating slave] instead of [slave keyboard (3)]. One day I might want to use the keyboard again, how would I find the it? Commented Jul 15, 2018 at 16:16

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



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

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


  • 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 :

    screenshot screenshot

  • 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, Ubuntu 17.10 and below)

[Desktop Entry]
Name=Clavier ON-OFF





[screenshot4 [screenshot5

  • This works well, thank you for explaining it clearly. There is one thing that I don't understand: how to make the icon change according to the shell script logic. I think this determined in part by "Icon=PATH/TO/YOUR/ICON" in the Desktop entry, I have used an absolute path, "/home/.../icon_on.png" as I don't know how else to use a ".desktop" file though I can see that this may prevent it switching icons. Could anyone provide a clue please?
    – Puffin
    Commented Dec 12, 2016 at 20:03
  • 1
    Hi, you're right about the absolute path in the .desktop file. Sorry but I don't know how to make dynamic changes for a launcher icon. According to that answer, is not possible at all : askubuntu.com/a/244951/458410. The icon in my script changes in notifications only.
    – mxdsp
    Commented Dec 20, 2016 at 10:00
  • Ah ha, ok that makes sense, mine does the same, thank you.
    – Puffin
    Commented Dec 20, 2016 at 18:47
  • 3
    A possible improvement: instead of storing state in a file you can check directly if the keyboard is disabled with this command: function is-disabled() { xinput --list --long | grep -A 1 "id=$1" | grep -q disabled }. That way everything works even if the keyboard is enabled/disabled by another program.
    – dshepherd
    Commented Feb 26, 2017 at 11:21
  • 2
    Another improvement migth be to automatically get the id by the name of the file. This is what I use: id=$(xinput list --id-only 'AT Translated Set 2 keyboard') Commented Aug 10, 2020 at 8:50

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"
  • 1
    Indeed device can be the device name as a string or the XID of the device (source man xinput) Commented Mar 13, 2020 at 15:48

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


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.

  • 2
    How would I enable again my keyboard? Commented Jun 12, 2019 at 3:14
  • @Rokibul Hasan, i8042.nokbd helped me a lot for my case.. in my laptop internal keyboard, some keys work and some not.. so I am keeping my external keyboard on laptops internal keyboard.. this causes problem at login screen. with your answer.. my problem is gone..
    – PRATAP
    Commented Jan 2, 2020 at 9:43
  • @GuilhermeParreira You must already have sorted a functioning keyboard from within your own user environment in order to proceed comfortably with the coding above. I did that and could still use the internal keyboard at start-up for the hard disk lock and for editing the boot-loader menu; earlier, though, I could not even change the bootstrapping passwords, for the fields were filled by volleys of characters. This helped me. The login into the Ubuntu system worked via the external keyboard only. Once you are in, you can revert the settings above in the same way you enabled them Commented Mar 13, 2020 at 16:23
  • Note that, once you disable the keyboard port, the command xinput --list will not show the internal keyboard any longer. So all bash scripts searching for the string AT Translated Set 2 keyboard will fail. This is logical because the keyboard has been disabled at a higher level than that the scripts look into. So you will not be able to reinstate the keyboard from inside Ubuntu in other ways than changing the boot loader configuration again and reboot. Commented Mar 13, 2020 at 18:00
  • Usually, I upvote posts just after get helped from the post. But this time I had to restart my laptop before upvoting :) @Rokibul Hasan, thanks man it helps me a lot.
    – Razib
    Commented Apr 20, 2021 at 23:12

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.`


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

  • 2
    this is not exactly what I need, I need to use my usb keyboard, but your code is very useful! ;)
    – atmon3r
    Commented Aug 21, 2012 at 22:28
  • Lock-keyboard-for-Baby will let you disable your internal keyboard while mainting the use of the external
    – LnxSlck
    Commented Aug 22, 2012 at 0:49
  • Brilliant. Lock-Keyboard-For-Baby works in Ubuntu 16.04 as well. I prefer to code using pen and paperbook keeping it on keyboard. This tiny utility solved my problem. For others, you might have to run sudo apt-get install libgtk2-perl before running the perl script
    – mac
    Commented Feb 1, 2017 at 8:05
  • "Quit Now", Quit Now or quit now no worky under 18.04 with desktop tower USB keyboard.
    – fleamour
    Commented Aug 9, 2018 at 19:10

One sure way to disable it is to unplug the signal cable. You need to pop up the keyboard for that. For information on how to do that, check out the Maintenance and Service Guide for the HP Pavilion dv9000 and dv9200 Notebook PC .

Now there is a way to disable the keyboard using xinput. T do that, just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the commands below.

To list the devices your X

xinput --list

To disable the keyboard:

xinput set-int-prop 2 "Device Enabled" 8 0

To enable the keyboard again:

xinput set-int-prop 2 "Device Enabled" 8 1

If you get a error about permissions, use the commands above with sudo.


Consequently, I discovered:

$ xinput float id#;sleep t;xinput reattach id# master#

t -time to sleep in seconds

id# and master# as mentioned above (top of page)

For example in my terminal:

$ xinput float 11;sleep 5;xinput reattach 11 3

Try running xmodmap -e 'keycode 24=' to disable just the Q key. If that works, you could add it it to your ~/.bashrc or global /etc/bash.bashrc file. I got this idea from here, which shows all the key-mappings.

  • 5
    Wouldn't this disable q in the external keyboard as well?
    – Sparhawk
    Commented Aug 30, 2013 at 5:07

Input device indicator allows you to enable and/or disable your devices from a menu. It uses xinput internally, but you do not need to open the terminal, list manually, type the command etc.

A menu listing devices that can be disabled or enabled.

It is in a PPA, so you can install it with

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 03BBACDA765F39D9A14EEDE4425F3F9343B40373
sudo add-apt-repository ppa:brandizzi/ppa
sudo apt install input-device-indicator

To invoke it you just need to execute input-device-indicator (which can be added to the session startup programs) or look for "Input Device Indicator" through the HUD (or whatever it is called these days.)


For what it's worth, based on previous answers and my own playing around, I created the following script, which I call toggle_keyboard.sh and place in my ~/bin path. I have a keyboard shortcut that runs it set to CtrlWinK.

Some problems with the previous answers and benefit of my script:

  • Relying on an id number with xinput fails when you reboot and the id number is changed. This happened to me when running xinput float 13. I ended up disabling the wrong hardware.
  • Relying on a file to hold the enabled/disabled state will fail if you reboot as well. The file will tell you the keyboard is disabled (if you disabled it with the script), but after a reboot it will be enabled again. My solution gets the enabled/disabled information from a parsed xinput command.
  • My script will work with any xinput device that shows up when you type xinput list --name-only. Just get the name and edit the top four variables. I use it for my laptop keyboard, webcam, touchscreen monitor and a few other things I use only once in a while.

# Toggle the laptop keyboard either on or off and notify the user about it

# Device name can be found by typing this command: xinput list --name-only
DEVICE_NAME="AT Translated Set 2 keyboard"
# The display name of the device in the notify-send popup

# Set these to the icons you want to use.
# If they are not found, the notification will still work.

function xinput_set_prop() {
        xinput set-prop "$DEVICE_NAME" "Device Enabled" $1

function notify_change() {
        if [ -f "$1" ]; then
                notify-send --urgency=low --icon="$1" "$2"
                notify-send --urgency=low "$2"

# Returns 1 if device is enabled, 0 if disabled
is_enabled=$(xinput list-props "$DEVICE_NAME" | grep "Device Enabled" | awk '{ print $4 }' | sed 's/[^0-9]*//g')

if [ $is_enabled -eq 1 ]; then
        # device is enabled, so disable it
        xinput_set_prop 0
        notify_change "$ICON_DISABLE" "$DEVICE_DISPLAY_NAME Disabled"
        # device is disabled, so enable it
        xinput_set_prop 1
        notify_change "$ICON_ENABLE" "$DEVICE_DISPLAY_NAME Enabled"

xinput float "AT Translated Set 2 keyboard"

After spending hours over years with different methods with different distros and releases. The above terminal command is what I rely on after problems..... I use this now with neon plasma and was using it a month ago in straight ubuntu 18.04. (needs applying after restart - can be placed in startup) * My built in keyboard on my HP Laptop that is damaged and starts typing which causes serious problems - I use a wireless keyboard and mouse - touchpad is on/off as part of KDE topbar options - neon/plasma 5). In system settings / autostart A text file with the following line of code is saved as a .sh file and set as executable (txt files properties)
xinput float "AT Translated Set 2 keyboard"

The text file is given a name > keyboardoff > and placed in autostart (executable) When you restart/start system > built in keyboard is switched off. (use xinput list to test)

  • "After spending hours over years with different methods with different distros and releases." I did the same and I was always getting the "attempt to access private resource denied". That was probably because I was using the devide id instead of its name. This answer worked fine and imho is the best answer by far. Commented Dec 25, 2020 at 6:03
  • By the way, to re-enable that keyboard try the command xinput reattach "AT Translated Set 2 keyboard" 3, where the number 3 is the id of the master keyboard (obtained from the xinput command) Commented Dec 25, 2020 at 6:04
#Disable Inbuilt Keyboard on Ubuntu

# Find Keyboard Device ID
KeyboardID=$(xinput list | grep "Translated Set 2 keyboard" | awk '{ gsub(/[[:alpha:]]|[[:punct:]]/," ")}1' | awk  '{print $3}')

# Find Master Device ID
MasterDeviceID=$(xinput list | grep "Translated Set 2 keyboard" | awk '{ gsub(/[[:alpha:]]|[[:punct:]]/," ")}1' | awk  '{print $4}')

# Command to disable Keyboard
xinput float $KeyboardID

# Command to enable Keyboard
xinput reattach $KeyboardID $MasterDeviceID

The methods mentioned earlier can be either too extreme, like i8042.nokbd, or limited to Xserver. However, there's another approach that achieves a similar result to the i8042.nokbd parameter while still being easy to revert, just like the X server methods.

To unbind the device from the relevant driver in an elevated terminal, execute:

echo -n 'serio0' > '/sys/bus/serio/drivers/atkbd/unbind'

To rebind or enable the keyboard again, use:

echo -n 'serio0' > '/sys/bus/serio/drivers/atkbd/bind'

Note: On some devices, the keyboard will automatically bind itself. To prevent this, you need to change the bind mode of the device from auto to manual by executing:

echo -n 'manual' | tee /sys/devices/platform/i8042/serio0/bind_mode

Also, note that the keyboard is not guaranteed to correspond to serio0, though this is usually the case.


Another interesting way to achieve similar results to xinput methods at a layer just below xserver or any modern display-input server is to force libinput to ignore inputs from the device by using the udev attribute LIBINPUT_IGNORE_DEVICE. For further instructions.

Yet another udev method is to not identify the keyboard as an input device by setting ENV{ID_INPUT}="",source.

Note:The first method is valid for a session only,you can create a udev rule or systemd service to have a persistent effect.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .