1) Open the CMD, input adb shell getevent> e: /test.txt // This command is used to retrieve the key event corresponding to the event
2) manually click Power button, press ctlr + C key to exit
3) Open the test.txt file and look for event inside, I crawled to the following results:
After 4) Event obtained, we can use it to send commands sendevent command, the specific code as follows
import os import time os.system("adb shell sendevent /dev/input/event0 1 116 1") os.system("adb shell sendevent /dev/input/event0 0 0 0") the time.sleep ( 10) to achieve a long-press operation //
Here we use the sleep function, set waiting for the event to achieve the purpose of long press physical buttons.