[Note: In the kernel code, documentation/input/input.txt describes the input devices.]
After detecting a USB keyboard, the system usually maps it to/dev/input/event0. You may use the cat command to confirm it:
# Cat/dev/input/event0
Garbled characters may occur when operating the USB keyboard.
You can also run the following command to view the association between devices and nodes:
# Cat/proc/bus/input/devices
My system is connected to a Logitech USB keyboard and outputs the following information:
I: Bus=0003 Vendor=046d Product=c31d Version=0110N: Name="Logitech USB Keyboard"P: Phys=usb-musb-hdrc-1/input0S: Sysfs=/devices/platform/musb-blackfin.0/musb-hdrc/usb1/1-1/1-1:1.0/input/input0U: Uniq=H: Handlers=kbd event0B: PROP=0B: EV=120013B: KEY=10000 7 ff9f207a c14057ff febeffdf ffefffff ffffffff fffffffeB: MSC=10B: LED=1fI: Bus=0003 Vendor=046d Product=c31d Version=0110N: Name="Logitech USB Keyboard"P: Phys=usb-musb-hdrc-1/input1S: Sysfs=/devices/platform/musb-blackfin.0/musb-hdrc/usb1/1-1/1-1:1.1/input/input1U: Uniq=H: Handlers=kbd event1B: PROP=0B: EV=1bB: KEY=2010000 397a d801d001 1e0000 0 0 0B: ABS=1 0B: MSC=10
The application can use the following program to read the USB key value:
#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <stdio.h>#include <linux/input.h>struct input_event buf;int main(int argc, char **argv){ int fd; int nread; fd = open("/dev/input/event0", O_RDONLY); if (fd < 0) { printf("fail to open usbdev.\n"); exit(1); } printf("--fd = %d--\n", fd); while (1) { nread = read(fd, &buf, sizeof(buf)); if (nread != 0) { printf("type : %d, code = %d, value = %d\n", buf.type, buf.code, buf.value); } } return 0;}