What are the commands needed to write events to / dev / input / eventX?

I am developing an android application that needs to be sent to touch events to / dev / input / eventX. I know that the structure of the C code to accomplish such a thing is as follows:

 struct input_event { struct timeval time; unsigned short type; unsigned short code; unsigned int value; }; 

To use such code, I need to install NDK . Instead, I want to run equivalent linux commands using Runtime.getRunTime.exec () in android, without the need to use NDK. Is there any way to do this?

If not, what is the rest of the C code needed to send the event? For example, how can I send a touch event with x = 200 and y = 300 in event0? I searched and I did not find a clear solution.

Thanks.

+2
source share
1 answer

I do not understand why you need to send the event to /dev/input/eventX directly. But if it can send via adb , you can enter a lot of type events on the device.

Try this on your computer:

adb shell input tap 200 300

Or this is on your Android device shell:

input tap 200 300

But he has a high delay due to external injection.

Read more about the input command here.

 Usage: input [<source>] <command> [<arg>...] The sources are: mouse keyboard joystick touchnavigation touchpad trackball stylus dpad touchscreen gamepad The commands and default sources are: text <string> (Default: touchscreen) keyevent [--longpress] <key code number or name> ... (Default: keyboard) tap <x> <y> (Default: touchscreen) swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen) press (Default: trackball) roll <dx> <dy> (Default: trackball) 
+3
source

Source: https://habr.com/ru/post/983281/


All Articles