1

I want to simulate pressing the power button on a rooted Samsung Galaxy Tab 2 GT-P5100 running Android 4.0.4 using the ADB shell.

To do this I changed the relevant permissions using:

adb shell
su
chmod 666 /dev/input/event1

How do I know whether this was successful?

I thought that the following command would display the lock screen:

input keyevent 116

I get no errors, but nothing happens...

Alternatively I used the text form of the key code which looks like this:

input keyevent KEY_POWER

In this case, the output is Killed - What does this mean?

Lastly, I tried:

sendevent dev/input/event1 1 116 1 ; sendevent dev/input/event1 1 116 0

With no luck :(

What am I doing wrong?

getevent -i /dev/input/event1

outputs the following:

add device 1: /dev/input/event1
  bus:      0000
  vendor:   0000
  product:  0000
  version:  0000
  name:     "sec_key"
  location: ""
  id:       ""
  version:  1.0.1
  events:
    KEY (0001):  0072  0073  0074
  input props:
    <none>

The key 0074 has the textual label KEY_POWER.

2 Answers 2

3

Power button press consists of a few events. You can check it by typing command:

adb shell getevent -l

and then press power button. On nexus 5 emulator the result is:

/dev/input/event0: EV_KEY KEY_POWER   DOWN                
/dev/input/event0: EV_SYN SYN_REPORT  00000000            
/dev/input/event0: EV_KEY KEY_POWER   UP                  
/dev/input/event0: EV_SYN SYN_REPORT  00000000 

The touch event input file /dev/input/event can be deferent from device to device. In this case it is event0.

Before writing events to device you have to change mode of touch event file:

adb shell
chmod 666 /dev/input/event0

All definitions of keys can be found in http://androidxref.com/4.4_r1/xref/prebuilts/ndk/6/platforms/android-9/arch-arm/usr/include/linux/input.h

The value of sendevent keys should be decimal

To emulate the power button press you have to write all those events :

adb shell sendevent /dev/input/event0 1  116  108                
adb shell sendevent /dev/input/event0 0  0    0            
adb shell sendevent /dev/input/event0 1  116  103                  
adb shell sendevent /dev/input/event0 0  0    0 

I tested it on Nexus 5 emulator and it works.

1

Because you're not sending in the right way. It's not enough to send only

sendevent dev/input/event1 1 116 1 ; sendevent dev/input/event1 1 116 0

Please just try the below one ;)

sendevent dev/input/event1 1 116 1 ; sendevent dev/input/event1 0 0 0 ;sendevent dev/input/event1 1 116 0 ;sendevent dev/input/event1 0 0 0

You must log in to answer this question.