How to "debug" a keyboard in Linux? Like pressing a key and seeing a code in a terminal

23,790

Solution 1

Try xev. It will display the keycodes that the X Window system sees when you press the keys you're interested in. You can use xmodmap to modify the mapping.

Solution 2

An awesome utility from linux-input called 'evtest' is excellent at debugging keyboard, mice, and joysticks. Function keys should work too.

apt-get install evtest

Sample output from pressing the caps lock key while evtest running:

Event: time 1398955189.226822, type 17 (EV_LED), code 1 (LED_CAPSL), value 1
Event: time 1398955189.226822, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70039
Event: time 1398955189.226822, type 1 (EV_KEY), code 58 (KEY_CAPSLOCK), value 0
Event: time 1398955189.226822, -------------- SYN_REPORT ------------

Since evtest uses /dev/input, you can use it from a TTY or SSH, with no Xserver running.

Solution 3

There are so-called event device files which are bound into a very low level of input layer. They reside in /dev/input/ directory, and you can read keycodes that are passed by virtual PS/2 keyboard by doing sudo hd /dev/input/by-path/platform-i8042-serio-0-event-kbd. If this command fails, just try that with each of /dev/input/eventX files: one of them will be bound to your keyboard.

Share:
23,790

Related videos on Youtube

Somebody still uses you MS-DOS
Author by

Somebody still uses you MS-DOS

Just kidding. MS-DOS, you broke my heart. No more.

Updated on September 17, 2022

Comments

  • Somebody still uses you MS-DOS
    Somebody still uses you MS-DOS over 1 year

    I didn't have an answer to my problem about adding additional keyboards in my Ubuntu 10.04. Questions mark is not working in my keyboard, only using Alt Gr key + W.

    So, I don't know if this is a problem with Ubuntu or Virtualbox itself (I'm running it inside a VM).

    It's an usb keyboard. HP KU-0316.

    I would like to debug this problem. The keyboard is plugged in, so when I press a key I believe something is being sent to my operating system, some code, I don't know. I would like to digg this problem, find some damn key code and find some damn *.conf file and manually fix my problem.

    So, do an application like this exist in Linux?

  • Somebody still uses you MS-DOS
    Somebody still uses you MS-DOS almost 14 years
    Exactly what I was thinking for! And when I press the key, nothing shoes... maybe a Virtualbox bug?
  • wpcarro
    wpcarro almost 5 years
    Any advice for when neither sudo hexdump /dev/input/by-path/*-kbd nor sudo hexdump /dev/input/event* has any output? My laptop keyboard works in BIOS but nowhere else. I can see output from the aforementioned commands only with my USB keyboard.