Reputation: 1688
I'm developing an android app that needs to send touch events to /dev/input/eventX. I know the C
code structure to do such a thing is the following:
struct input_event {
struct timeval time;
unsigned short type;
unsigned short code;
unsigned int value;
};
To use such a code, I need to set 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 that?
If no, what are the rest of C
code needed to send an event? For example, how can I send a touch event at x=200 and y=300 to event0? I searched and I didn't find a clear solution.
Thanks.
Upvotes: 4
Views: 2086
Reputation: 4932
I'm not clear about why you need to send event to /dev/input/eventX
directly. But if it can send via adb
, you can inject many type events to device.
Try this on your computer:
adb shell input tap 200 300
Or this on your android device shell:
input tap 200 300
But it has a high delay because of outside injection.
More info about input
command see 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)
Upvotes: 3