In uClinux, the application obtains the USB key value.

Source: Internet
Author: User

[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;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.