Compile the detection program for input devices in Linux

Source: Internet
Author: User
Recently played under the Android-x86 of eclair, theme style compared to the previous 1.6 good-looking a lot, but also added a lot of features not available before. However, the touch screen cannot be used. You can run the getevent command on the terminal to view the event information. The obtained absolute coordinates vary greatly (4096*4096 ). So I tried to solve the problem myself. At the same time, I tested it in Ubuntu and found that there was no getevent command. Of course, I could use CAT/dev/inpu/eventx to view the event information, but it showed a bunch of garbled characters. What should I do? Then write a test applet for the Linux input device to detect the problem. The test result shows that the problem is the same as that in Android-there is no correction, and it is also a small achievement. Next, we should correct the dig touch screen :-)

Now let's put the written test program for your reference:
In the code, macros define key_dev, mou_dev, tous_dev, and toup_dev as the file paths of the Linux keyboard, mouse, touch screen, and touchpad devices. Different Systems and machines may be different, you can use CAT/proc/bus/input/devices to view the device files of your machine.

Compile the executable file with GCC-O outfilename filename, and then run the./outfilename file. Note that you need to modify the generated Executable File Permission. If you do not want to modify the permission, use sudo./outfilename. Currently, you have not added the function of switching the device during the test. You can only use Ctrl + Z to end the program and re-execute the file. If you have time, try again ~~

# Include
# Include
# Include
# Include
# Include
# Define key_dev "/dev/input/event5"
# Define mou_dev "/dev/input/event6"
# Define tous_dev "/dev/input/event7"
# Define toup_dev "/dev/input/event11"

Static int ts_fd =-1;
Static struct input_event data;

Static int init_device (char * ts_dev)
{
If (ts_fd = open (ts_dev, o_rdonly) <0)
{
Printf ("error open % s/n", ts_dev );
Return-1;
}
Return ts_fd;
}

Static int test_key ()
{
If (init_device (key_dev) <0)
Return-1;
While (1)
{
Read (ts_fd, & Data, sizeof (data ));
If (data. type = ev_key)
Printf ("type: ev_key, event = % d, value = % d/N", Data. Code, Data. value );
}
Return 0;
}

Static int test_mouse ()
{
If (init_device (mou_dev) <0)
Return-1;
While (1)
{
Read (ts_fd, & Data, sizeof (data ));
If (data. type = ev_key)
{
Printf ("type = ev_key, code = % s, value = % d/N ",
Data. Code = btn_left? "Mouse_left ":
Data. Code = btn_right? "Mouse_right ":
Data. Code = btn_middle? "Mouse_middle ":
Data. Code = btn_side? "Mouse_side ":
"Unkonw", Data. value );
}
Else if (data. type = ev_rel)
{
Printf ("type = ev_abs, code = % s, value = % d/N ",
Data. Code = rel_x? "Abs_x ":
Data. Code = rel_y? "Abs_y ":
Data. Code = abs_wheel? "Mouse_wheel ":
Data. Code = abs_pressure? "Abs_pressure ":
"Unkown", Data. value );
}
}
Return 0;
}

Static int test_touch_screen ()
{
If (init_device (tous_dev) <0)
Return-1;
While (1)
{
Read (ts_fd, & Data, sizeof (data ));
If (data. type = ev_key)
{
Printf ("type: ev_key, event = % s, value = % d/n ",
Data. Code = btn_touch? "Btn_touch": "unkown", Data. value );
}
Else if (data. type = ev_abs)
{
Printf ("type: ev_abs, event = % s, value = % d/n ",
Data. Code = abs_x? "Abs_x ":
Data. Code = abs_y? "Abs_y ":
Data. Code = abs_pressure? "Abs_pressure ":
"Unkown", Data. value );
}
}
Return 0;
}

Static int test_touch_pancel ()
{
If (init_device (toup_dev) <0)
Return-1;
While (1)
{
Read (ts_fd, & Data, sizeof (data ));
If (data. type = ev_key)
{
Printf ("type = ev_key, code = % s, value = % d/N ",
Data. Code = btn_left? "Mouse_left ":
Data. Code = btn_right? "Mouse_right ":
Data. Code = btn_middle? "Mouse_middle ":
Data. Code = btn_side? "Mouse_side ":
"Unkonw", Data. value );
}
Else if (data. type = ev_rel)
{
Printf ("type = ev_abs, code = % s, value = % d/N ",
Data. Code = rel_x? "Abs_x ":
Data. Code = rel_y? "Abs_y ":
Data. Code = abs_wheel? "Mouse_wheel ":
Data. Code = abs_pressure? "Abs_pressure ":
"Unkown", Data. value );
}
}
Return 0;
}

Int main ()
{
Static int I;
Select: printf ("Please select device:/n0.keyboard/n1.mouse/n2.touchscreen/n3.touchpancel/N ");
Scanf ("% d", & I );
Switch (I ){
Case 0:
Test_key ();
Break;
Case 1:
Test_mouse ();
Break;
Case 2:
Test_touch_screen ();
Break;
Case 3:
Test_touch_pancel ();
Break;
Default:
Printf ("wrong device, please select again! /N ");
Break;
}
Goto select;
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.