There's an answered question about sending long presses on android, the problem with it is that
- None of the answers actually work some use outdated API, some API that is too new
- I need to send key down event and only later decide to lift the key
From the top voted answer on linked question I have this code to start with:
adb shell sendevent /dev/input/event2 1 172 1
adb shell sendevent /dev/input/event2 0 0 0
timeout 1
adb shell sendevent /dev/input/event2 1 172 0
adb shell sendevent /dev/input/event2 0 0 0
These commands do not work, the author of the answer also didn't drop a single word about what the commands do and why. Through some experiments I figured out that:
- It must be
/dev/input/event0
instead ofevent2
- Changing any of the numbers results in nothing happening
adb shell sendevent /dev/input/event2 0 0 0
is required. What does it do I don't know
Now I need to send key up/down events for keys including those that are not on the device (for example KEYCODE_DPAD_DOWN), so adb shell getevent
doesn't help that much - I can't press keys that are not there to be pressed. I'm working with Android 4.1.2 Samsung phone.
Also can anyone explain to me what is the 0 0 0
event?