The input subsystem of Linux gets the device Name

Source: Internet
Author: User

The Linux kernel provides an input subsystem, and the input subsystem creates a node of our hardware input device under the/dev/input/path, which in general is named after EVENTXX in our phone, such as event0,event1 and so on, You can take advantage of eviocgname to get this event node name. This is the source point for processing data for the input event in Android.


---------------


The dev/input/event* corresponding device Name can be obtained through the IOCTL command eviocgname.

Instance:


Openinput (const char* inputname) {
int FD =-1;
const char *dirname = "/dev/input";
Char Devname[path_max];
Char *filename;
DIR *dir;
struct Dirent *de;
dir = Opendir (dirname);
if (dir = = NULL)
return-1;
strcpy (Devname, dirname);
filename = devname + strlen (devname);
*filename++ = '/';
while ((de = Readdir (dir))) {
if (de->d_name[0] = = '. ' &&
(de->d_name[1] = = '/' | |
(de->d_name[1] = = '. ' && de->d_name[2] = = ' + ')))
Continue
strcpy (filename, de->d_name);
FD = open (Devname, o_rdonly);
if (fd>=0) {
Char name[80];
if (IOCTL (FD,Eviocgname(sizeof (name)-1), &name) < 1) {
Name[0] = ' + ';
}
if (!strcmp (name, InputName)) {
Break
} else {
Close (FD);
FD =-1;
}
}
}
Closedir (dir);
Loge_if (fd<0, "couldn ' t find '%s ' input device", inputname);
Logi_if (fd>=0, "Found '%s ' input device in%s", InputName, dirname);
return FD;

}


===========================

http://blog.csdn.net/andyhuabing/article/details/7006688

The input subsystem of Linux gets the device Name

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.