Linux Read input device demo

Source: Internet
Author: User

/******************************************************************* * Linux Read input device demo * Description: * This article is mainly to understand the previous colleague wrote input device a demo program. * 2016-3-24 Shenzhen Nanshan Ping Shan village Zengjianfeng **************************************************************** **/#include<stdio.h>#include<unistd.h>#include<sys/types.h>#include<fcntl.h>#include<linux/input.h>intMainintargcChar**argv) {    intFD; structinput_event ev; //Judging Parameters    if(ARGC <2) {printf ("Usage:%s <input device>\n", argv[0]); return 0; }    //turn on the deviceFD = open (argv[1], O_RDWR); if(FD <0) {printf ("Open%s", argv[1]);        Fflush (stdout); Perror (" "); return 0; }    //Loop Read     while(1) {        //reading DataRead (FD, &ev,sizeof(structinput_event)); //Print the current trigger typeprintf"ev = =%x \ n", Ev.type);
Switch(ev.type) { Caseev_syn:printf ("-------------------------\ n"); Break; //Key Caseev_key:printf ("key down/up:%d \ n", Ev.code); Break; //Mouse Caseev_rel:printf ("Mouse:"); if(Ev.code = =rel_x) {printf ("X--%d\n", Ev.value); } Else if(Ev.code = =rel_y) {printf ("y--%d\n", Ev.value); } Break; //Touch Screen Caseev_abs:printf ("TS:"); if(Ev.code = =abs_x) {printf ("X--%d\n", Ev.value); } Else if(Ev.code = =abs_y) {printf ("y--%d\n", Ev.value); } Else if(Ev.code = =abs_pressure) {printf ("Pressure:%d\n", Ev.value); } Break; }} close (FD); return 0;}

Linux Read input device demo

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.