How To: Fix USB Keyboards Missing the First Keypress in Linux

I use my laptop as a desktop with an external monitor, mouse & keyboard, and found that recently the keyboard would keep missing the first character of input – and it was driving me nuts. After much googling I found a blog post over at wulftone.com that narrowed the issue down to a USB sleep problem, and described how to blacklist a USB keyboard from going into sleep mode – and it works great!

The way to fix this issue is:

1 – Find the details of your USB keyboard via the lsusb command, like this:

$ lsusb
Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 004: ID 1bcf:2885 Sunplus Innovation Technology Inc. ASUS Webcam
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 003: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 003 Device 002: ID 045e:00dd Microsoft Corp. Comfort Curve Keyboard 2000 V1.0  <--- Ch-ching!
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

2 – Once you can see your keyboard, if you can’t remember which way the vendor ID and product ID go (it’s that very order), you can get the details (in this case looking at the Microsoft keyboard on bus 003, device 002) like this:

$ lsusb -v -s 003:002
 
Bus 003 Device 002: ID 045e:00dd Microsoft Corp. Comfort Curve Keyboard 2000 V1.0
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x045e Microsoft Corp.                   <--- Vendor ID.  Do not take the 0x prefix.
  idProduct          0x00dd Comfort Curve Keyboard 2000 V1.0  <--- Product ID. Do not take the 0x prefix.
  bcdDevice            1.73
  ... More details than most people are interested in ...

3 – Next, edit (or create if necessary) the file: /etc/udev/rules.d/91-local.rules and place the following contents into it:

ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="YOUR-KEYBOARD-VENDOR-ID", ATTR{idProduct}=="YOUR-KEYBOARD-PRODUCT_ID", TEST=="power/control", ATTR{power/control}="on"

So for my USB keyboard I entered:

ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="045E", ATTR{idProduct}=="00DD", TEST=="power/control", ATTR{power/control}="on"

4 – Finally, with that done you can reload the udev rules with the following and you should be all set:

sudo udevadm control --reload-rules

As a final note, I found that this (bizarrely) didn’t work when I used the lowercase hex codes (i.e. 045e & 00dd) – I had to put them to uppercase (045E & 00DD) for it to kick in!

Sanity restored! =D

P.S. If you want to disable your first (i.e. laptop) keyboard and/or are using laptop-mode-tools then the wulftone article has you covered. So many thanks to Trevor Bortin for this fix!

6 thoughts on “How To: Fix USB Keyboards Missing the First Keypress in Linux”

  1. Hey,

    First of all, thank you for posting this. I really hated typing my password twice when I came back to my computer because the keyboard sat for too long and ignored the first key press.

    I had the exact same problem, except I had to change a few things:

    SUBSYSTEM for my keyboard device was “input” and not “usb”

    Also, the input device itself didn’t have the idVendor and idProduct attributes, so I used ATTRS to include parent devices’ attributes.

    My final rule looked like this:

    ACTION==”add”, SUBSYSTEM==”input”, ATTRS{idVendor}==”2516″, ATTRS{idProduct}==”0015″, TEST==”power/control”, ATTR{power/control}=”on”

  2. Thank you for this post!

    I recently had this problem too, which I guess was either a new kernel install or related to some modifications I’d made to allow a USB controller to sleep, so that my laptop could be made to suspend properly.

    So glad you posted this – it was starting to seriously hamper my productivity!!

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.