Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use adb to send a longpress key event?

Tags:

android

adb

I can use something like:

adb shell input keyevent 4

and this will send a single 'Back' button press to my device. How can I send a longpress?

Thanks

like image 643
whoabackoff Avatar asked Jun 21 '12 16:06

whoabackoff


3 Answers

You can try this command:

adb shell input touchscreen swipe 170 187 170 187 2000

Your application position on screen is 170, 187; delay time is 2000 (ms);

Long press HOME key:

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

You can goto cmd and type adb shell getevent | find "event2" ; long press HOME key to see more.

like image 76
Nguyen Duc Han Avatar answered Nov 02 '22 19:11

Nguyen Duc Han


Since this commit in Android 4.4 it is possibile to use:

adb shell input keyevent --longpress KEYCODE_L

This other commit further improved the behaviour.

like image 27
Nick Chalko Avatar answered Nov 02 '22 21:11

Nick Chalko


When you want to delete something or repeat some Event or just input a lot of numbers, you can use code like the following. It will imitate a longpress on a keyboard:

adb shell input keyevent KEYCODE_FORWARD_DEL KEYCODE_FORWARD_DEL KEYCODE_FORWARD_DEL //delete 3 times


adb shell input keyevent KEYCODE_1 KEYCODE_1 KEYCODE_1 //input value '111'

You can repeat the event or input things without limits, just like a Longpress on the key. It's the same thing. You can define your own longpass and times Now

like image 1
Ovi Avatar answered Nov 02 '22 21:11

Ovi