Note

Updated on 2010-12-04T00:35:15Z: This method is not best way to disable a laptop keyboard, please read the xinput method.

I have been waiting to disable my laptop keyboard since my external one is back. I dont want me typing on laptop, but I was so used to it. I want to be able to switch at anytime I want with external keyboard, of course.

After digging around. Here is some information I knew about my keyboard:

$ dmesg | grep keyboard
input: AT Translated Set 2 keyboard as /devices/platform/i8042/serio0/input/input3
$ /sys/devices/platform/i8042/serio0/
total 0
-rw-r--r-- 1 root root 4096 Aug 22 08:25 bind_mode
-r--r--r-- 1 root root 4096 Aug 22 08:25 description
lrwxrwxrwx 1 root root    0 Aug 22 08:25 driver -> ../../../../bus/serio/drivers/atkbd
--w------- 1 root root 4096 Aug 22 05:53 drvctl
-r--r--r-- 1 root root 4096 Aug 22 07:21 err_count
-rw-r--r-- 1 root root 4096 Aug 22 08:25 extra
-rw-r--r-- 1 root root 4096 Aug 22 08:25 force_release
drwxr-xr-x 2 root root    0 Aug 22 08:25 id
drwxr-xr-x 3 root root    0 Aug 22 07:21 input
-r--r--r-- 1 root root 4096 Aug 22 08:25 modalias
drwxr-xr-x 2 root root    0 Aug 22 08:25 power
-rw-r--r-- 1 root root 4096 Aug 22 08:25 scroll
-rw-r--r-- 1 root root 4096 Aug 22 05:53 set
-rw-r--r-- 1 root root 4096 Aug 22 07:21 softraw
-rw-r--r-- 1 root root 4096 Aug 22 07:21 softrepeat
lrwxrwxrwx 1 root root    0 Aug 22 08:25 subsystem -> ../../../../bus/serio
-rw-r--r-- 1 root root 4096 Aug 22 08:25 uevent
$ ll /sys/devices/platform/i8042/serio0/input/input3/
total 0
drwxr-xr-x 2 root root    0 Aug 22 08:24 capabilities
lrwxrwxrwx 1 root root    0 Aug 22 08:24 device -> ../../../serio0
drwxr-xr-x 3 root root    0 Aug 22 08:24 event3
drwxr-xr-x 2 root root    0 Aug 22 08:24 id
-r--r--r-- 1 root root 4096 Aug 22 08:24 modalias
-r--r--r-- 1 root root 4096 Aug 22 08:24 name
-r--r--r-- 1 root root 4096 Aug 22 08:24 phys
drwxr-xr-x 2 root root    0 Aug 22 08:24 power
lrwxrwxrwx 1 root root    0 Aug 22 08:24 subsystem -> ../../../../../../class/input
-rw-r--r-- 1 root root 4096 Aug 22 08:24 uevent
-r--r--r-- 1 root root 4096 Aug 22 08:24 uniq

I was poking at the files in the directories above to see if I could do something. I couldnt. So I googled, then I found this page, which showed me some possibility. There is a link to another page about AT keyboard controller. Its a huge help. Basically, you send 0xae to port 0x64 to enable keyboard and 0xad to disable.

I wrote a simple C code:

#include <unistd.h>
#include <sys/io.h>

#define I8042_COMMAND_REG 0x64

int main(int argc, char *argv[]) {
  char data = 0xae; // enable keyboard

  ioperm(I8042_COMMAND_REG, 1, 1);

  if (argc == 2 && argv[1][0] == '0')
    data = 0xad; // disable keyboard
  outb(data, I8042_COMMAND_REG);
  return 0;
  }

Note

Updated on 2014-05-29T06:18:30Z: A Python port code of this C code using PortIO library.

You run it anything other than sudo ./command 01 will enable the keyboard, otherwise keyboard gets disabled. I tried to read the keyboard status and toggled the status, but funny thing kept coming up. Either the status is incorrect or keyboard didnt get enabled/disabled. I am thinking it might be something to do with Kernels code (/usr/src/linux/drivers/input/serio/i8042*) or I just missed something.

And this thread has some information about USB keyboard and mentioned i8042.nokbd in Kernel boot parameter will not enable the keyboard. But this doesnt like the solution I want.

I suggest that you place a launcher where your mouse can access and set up a sudo for running that command passwordlessly, just in case.


[1]You need root privilege to give the program to operator on the port using ioperm(). If you run without the privilege, you will see Segmentation fault.