Reputation: 4393
I'm unsure if the question about injecting events via adb is supposed to be in StackOverflow or Android Enthusiasts, please move it if it doesn't belong here.
Anyway, my question is as follows.
I obviously have to determine the "type" of device for sending and receiving events. I can't obviously send a touch event to the keypad device.
After a lot of research I found the sendevent
and getevent
commands.
So, I want to send a long press to the power button of a phone.
I use this currently:
sendevent /dev/input/event3 1 116 0
sendevent /dev/input/event3 1 116 1
This works on the HTC Wildfire(click on the link for the input devices) because the keypad contains the power button and 116
happens to be the scan code for the power key.
I know what /dev/input/event3/
and 116
and 0 or 1
stand for. What does the 1
in-between /dev/input/event3/
and 116
stand for? How do I obtain it?
Moving on to the Nexus 4. Now, I've noticed that it has a separate powerkey and keypad handler
[EDIT]
Found this regarding sendevent
and getevent
on XDA.
Upvotes: 0
Views: 4155
Reputation: 31686
The 1
"in-between /dev/input/event3/ and 116" stands for EV_KEY event type constant:
- EV_KEY: Used to describe state changes of keyboards, buttons, or other key-like devices.
You could have found that on your own if you had run getevent -l /dev/input/event3/
and pressed the power key.
Also to find out the power key input device name I would recommend parsing output of getevent -pl
instead of contents of /proc/bus/input/devices
. The device you are looking for has KEY_POWER
listed in the events section:
add device X: /dev/input/eventX
name: "xxxxxxxxxx"
events:
KEY (0001): KEY_POWER
And the proper long power key press sequence (as in press and hold for 1 second and then release) would be:
sendevent /dev/input/eventX 1 116 1
sendevent /dev/input/eventX 0 0 0
sleep 1
sendevent /dev/input/eventX 1 116 0
sendevent /dev/input/eventX 0 0 0
Note: getevent -pl
is not available for Gingerbread and below.
Upvotes: 4