6

I am trying to wake a device up using the following adb command

adb input keyevent 26

This correctly emulates the power button keypress if the screen is on, but will not turn the screen on if it was off and locked.

Can anyone suggest why?

2
  • I mean to wake it up from its locked state with the screen turned off. In normal use i would press the power button once to wake the screen up so i can slide to unlock Aug 22, 2013 at 21:22
  • Do you need this because your power button is broken? (In this case, you could maybe give it a call to wake it up if you really didn't think of that.) Anyway, I think you might have to use the getevent / sendevent commands.
    – cLick
    Aug 22, 2013 at 21:41

4 Answers 4

3

This is an old post, but this command should wake up any device.

adb shell input keyevent KEYCODE_WAKEUP

2

My phone does this, too. I wish I knew why.

I seem to have had some success with the sendevent command (adb shell sendevent). (Not much documentation on sendevent, unfortunately.)

First, I had to locate the Power Key device via getevent -i. In my case, I found /dev/input/event4 had a name like pmic8xxx_pwrkey, and used this for my sendevent call.

# sendevent --help
use: sendevent device type code value

To use sendevent, I also had to find the type and code. In the getevent device, it listed events, and I used event "KEY" (which corresponded to a value of 1) for the type parameter, and then used the first value which followed that event type as the code parameter, 0074 (this is a hex value, 0074 represents the decimal value 116) in my case. For the value parameter, I used 1 and 0 for on/down and off/up.

Constructing the command, I sent this to emulate a power button press:

sendevent /dev/input/event4 1 116 1
sleep 1 # you may want to include this line, especially if you use this code in a script
sendevent /dev/input/event4 1 116 0

I had to wait about five seconds before my screen turned on, but eventually it did wake.

After further use, this seems to work only when my device is not charging.

0
0

I found that on my Moto MB865 (Atrix 2) sending menu key event turns the screen back on:

adb shell input keyevent 82
-1

did you try keyevent for power button ?

adb shell input keyevent KEYCODE_POWER

3
  • doesn't work for me on Nexus 7 for some reason
    – JPM
    Oct 27, 2014 at 21:28
  • KEYCODE_POWER is 26.
    – palswim
    May 24, 2015 at 5:11
  • @JPM if your intention is to block device vía pwr button you could also trigger the screen off, it will "block" your device too, and probably you will not need to unblock it when reactivated. I found lot of strange behaviors playing keycodes and Macrodroid blocks. I tried code 26 with no luck but finally set screen of did the trick to avoid unwanted tap's on the screen. palswin answer is soo god, let you a way to try to identify yours if for some reason has been changed.
    – m3nda
    Nov 28, 2017 at 19:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .