What is the basic difference between adb shell input keyevent
and adb shell sendevent
? Which one should I use for inputting a character? Are the keycodes the same that we pass to both the commands?
8 Answers
By adb shell input keyevent
, either an event_code
or a string
will be sent to the device.
usage: input [text|keyevent]
input text <string>
input keyevent <event_code>
Some possible values for event_code
are:
0 --> "KEYCODE_UNKNOWN"
1 --> "KEYCODE_MENU"
2 --> "KEYCODE_SOFT_RIGHT"
3 --> "KEYCODE_HOME"
4 --> "KEYCODE_BACK"
5 --> "KEYCODE_CALL"
6 --> "KEYCODE_ENDCALL"
7 --> "KEYCODE_0"
8 --> "KEYCODE_1"
9 --> "KEYCODE_2"
10 --> "KEYCODE_3"
11 --> "KEYCODE_4"
12 --> "KEYCODE_5"
13 --> "KEYCODE_6"
14 --> "KEYCODE_7"
15 --> "KEYCODE_8"
16 --> "KEYCODE_9"
17 --> "KEYCODE_STAR"
18 --> "KEYCODE_POUND"
19 --> "KEYCODE_DPAD_UP"
20 --> "KEYCODE_DPAD_DOWN"
21 --> "KEYCODE_DPAD_LEFT"
22 --> "KEYCODE_DPAD_RIGHT"
23 --> "KEYCODE_DPAD_CENTER"
24 --> "KEYCODE_VOLUME_UP"
25 --> "KEYCODE_VOLUME_DOWN"
26 --> "KEYCODE_POWER"
27 --> "KEYCODE_CAMERA"
28 --> "KEYCODE_CLEAR"
29 --> "KEYCODE_A"
30 --> "KEYCODE_B"
31 --> "KEYCODE_C"
32 --> "KEYCODE_D"
33 --> "KEYCODE_E"
34 --> "KEYCODE_F"
35 --> "KEYCODE_G"
36 --> "KEYCODE_H"
37 --> "KEYCODE_I"
38 --> "KEYCODE_J"
39 --> "KEYCODE_K"
40 --> "KEYCODE_L"
41 --> "KEYCODE_M"
42 --> "KEYCODE_N"
43 --> "KEYCODE_O"
44 --> "KEYCODE_P"
45 --> "KEYCODE_Q"
46 --> "KEYCODE_R"
47 --> "KEYCODE_S"
48 --> "KEYCODE_T"
49 --> "KEYCODE_U"
50 --> "KEYCODE_V"
51 --> "KEYCODE_W"
52 --> "KEYCODE_X"
53 --> "KEYCODE_Y"
54 --> "KEYCODE_Z"
55 --> "KEYCODE_COMMA"
56 --> "KEYCODE_PERIOD"
57 --> "KEYCODE_ALT_LEFT"
58 --> "KEYCODE_ALT_RIGHT"
59 --> "KEYCODE_SHIFT_LEFT"
60 --> "KEYCODE_SHIFT_RIGHT"
61 --> "KEYCODE_TAB"
62 --> "KEYCODE_SPACE"
63 --> "KEYCODE_SYM"
64 --> "KEYCODE_EXPLORER"
65 --> "KEYCODE_ENVELOPE"
66 --> "KEYCODE_ENTER"
67 --> "KEYCODE_DEL"
68 --> "KEYCODE_GRAVE"
69 --> "KEYCODE_MINUS"
70 --> "KEYCODE_EQUALS"
71 --> "KEYCODE_LEFT_BRACKET"
72 --> "KEYCODE_RIGHT_BRACKET"
73 --> "KEYCODE_BACKSLASH"
74 --> "KEYCODE_SEMICOLON"
75 --> "KEYCODE_APOSTROPHE"
76 --> "KEYCODE_SLASH"
77 --> "KEYCODE_AT"
78 --> "KEYCODE_NUM"
79 --> "KEYCODE_HEADSETHOOK"
80 --> "KEYCODE_FOCUS"
81 --> "KEYCODE_PLUS"
82 --> "KEYCODE_MENU"
83 --> "KEYCODE_NOTIFICATION"
84 --> "KEYCODE_SEARCH"
85 --> "TAG_LAST_KEYCODE"
The sendevent
utility sends touch or keyboard events, as well as other events for simulating the hardware events. Refer to this article for details: Android, low level shell click on screen.
-
1Hi @chwentong! Can you please help me with pointing to any place explaining “input text
” more detailed way? I can’t find anything about it, similar to http://developer.android.com/reference/android/view/KeyEvent.html Thanks! – stansult Jul 03 '12 at 00:14 -
3Hi! May I ask how can I enter the string containing space in a windows command line console? I try to enter `>adb shell input text "a b"` but not work. – Wei Yang Aug 08 '13 at 22:45
-
1where did you gett the information of the "input" command? what other features are hidden from the documentation (here : http://developer.android.com/tools/help/adb.html ) ? – android developer Mar 01 '14 at 23:16
-
7@WeiYang, try this , >adb shell input text "a%sb" – Natan Lotério Feb 12 '15 at 12:41
-
3This post was very helpful when the screen of my Android tablet broke and it wouldn't respond to touches. I was able to "type" the pin by using adb shell input keyevent and find my way around. Thanks! – j0aqu1n Mar 26 '15 at 13:59
-
Can adb send the text that we store in a variable? I tried using `system('adb shell input text ('variable')` and it is not sending anything. I have a variable, that stores random generated numbers – Emjey Mar 21 '17 at 17:30
-
Is there one for "Select all" ? Maybe CTRL+A somehow? – android developer Nov 23 '21 at 18:59
-
Just so this exists somewhere on the internet - I now use `input keyevent 187` to bring up the recent tasks screen on my Ouya (maybe need to turn off "kill background apps" in dev settings) when the controller stops working in RetroArch after I put the device to sleep or reconnect the controller and RetroArch adds it as another player or something. (Pulling up another screen and then back to RetroArch can fix it, for some reason.) – Erhannis Feb 18 '22 at 23:48
-
is it still valid in 2023 – Dipendra Sharma Apr 07 '23 at 18:27
Updating:
Using adb shell input
:
Insert text:
adb shell input text "insert%syour%stext%shere"
(obs: %s means SPACE)
..
Event codes:
adb shell input keyevent 82
(82 ---> MENU_BUTTON)
"For more keyevents codes see list below"
..
Tap X,Y position:
adb shell input tap 500 1450
To find the exact X,Y position you want to Tap go to:
Settings > Developer Options > Check the option POINTER SLOCATION
..
Swipe X1 Y1 X2 Y2 [duration(ms)]:
adb shell input swipe 100 500 100 1450 100
in this example X1=100, Y1=500, X2=100, Y2=1450, Duration = 100ms
..
LongPress X Y:
adb shell input swipe 100 500 100 500 250
we utilise the same command for a swipe to emulate a long press
in this example X=100, Y=500, Duration = 250ms
..
Event Codes Updated List:
0 --> "KEYCODE_0"
1 --> "KEYCODE_SOFT_LEFT"
2 --> "KEYCODE_SOFT_RIGHT"
3 --> "KEYCODE_HOME"
4 --> "KEYCODE_BACK"
5 --> "KEYCODE_CALL"
6 --> "KEYCODE_ENDCALL"
7 --> "KEYCODE_0"
8 --> "KEYCODE_1"
9 --> "KEYCODE_2"
10 --> "KEYCODE_3"
11 --> "KEYCODE_4"
12 --> "KEYCODE_5"
13 --> "KEYCODE_6"
14 --> "KEYCODE_7"
15 --> "KEYCODE_8"
16 --> "KEYCODE_9"
17 --> "KEYCODE_STAR"
18 --> "KEYCODE_POUND"
19 --> "KEYCODE_DPAD_UP"
20 --> "KEYCODE_DPAD_DOWN"
21 --> "KEYCODE_DPAD_LEFT"
22 --> "KEYCODE_DPAD_RIGHT"
23 --> "KEYCODE_DPAD_CENTER"
24 --> "KEYCODE_VOLUME_UP"
25 --> "KEYCODE_VOLUME_DOWN"
26 --> "KEYCODE_POWER"
27 --> "KEYCODE_CAMERA"
28 --> "KEYCODE_CLEAR"
29 --> "KEYCODE_A"
30 --> "KEYCODE_B"
31 --> "KEYCODE_C"
32 --> "KEYCODE_D"
33 --> "KEYCODE_E"
34 --> "KEYCODE_F"
35 --> "KEYCODE_G"
36 --> "KEYCODE_H"
37 --> "KEYCODE_I"
38 --> "KEYCODE_J"
39 --> "KEYCODE_K"
40 --> "KEYCODE_L"
41 --> "KEYCODE_M"
42 --> "KEYCODE_N"
43 --> "KEYCODE_O"
44 --> "KEYCODE_P"
45 --> "KEYCODE_Q"
46 --> "KEYCODE_R"
47 --> "KEYCODE_S"
48 --> "KEYCODE_T"
49 --> "KEYCODE_U"
50 --> "KEYCODE_V"
51 --> "KEYCODE_W"
52 --> "KEYCODE_X"
53 --> "KEYCODE_Y"
54 --> "KEYCODE_Z"
55 --> "KEYCODE_COMMA"
56 --> "KEYCODE_PERIOD"
57 --> "KEYCODE_ALT_LEFT"
58 --> "KEYCODE_ALT_RIGHT"
59 --> "KEYCODE_SHIFT_LEFT"
60 --> "KEYCODE_SHIFT_RIGHT"
61 --> "KEYCODE_TAB"
62 --> "KEYCODE_SPACE"
63 --> "KEYCODE_SYM"
64 --> "KEYCODE_EXPLORER"
65 --> "KEYCODE_ENVELOPE"
66 --> "KEYCODE_ENTER"
67 --> "KEYCODE_DEL"
68 --> "KEYCODE_GRAVE"
69 --> "KEYCODE_MINUS"
70 --> "KEYCODE_EQUALS"
71 --> "KEYCODE_LEFT_BRACKET"
72 --> "KEYCODE_RIGHT_BRACKET"
73 --> "KEYCODE_BACKSLASH"
74 --> "KEYCODE_SEMICOLON"
75 --> "KEYCODE_APOSTROPHE"
76 --> "KEYCODE_SLASH"
77 --> "KEYCODE_AT"
78 --> "KEYCODE_NUM"
79 --> "KEYCODE_HEADSETHOOK"
80 --> "KEYCODE_FOCUS"
81 --> "KEYCODE_PLUS"
82 --> "KEYCODE_MENU"
83 --> "KEYCODE_NOTIFICATION"
84 --> "KEYCODE_SEARCH"
85 --> "KEYCODE_MEDIA_PLAY_PAUSE"
86 --> "KEYCODE_MEDIA_STOP"
87 --> "KEYCODE_MEDIA_NEXT"
88 --> "KEYCODE_MEDIA_PREVIOUS"
89 --> "KEYCODE_MEDIA_REWIND"
90 --> "KEYCODE_MEDIA_FAST_FORWARD"
91 --> "KEYCODE_MUTE"
92 --> "KEYCODE_PAGE_UP"
93 --> "KEYCODE_PAGE_DOWN"
94 --> "KEYCODE_PICTSYMBOLS"
...
122 --> "KEYCODE_MOVE_HOME"
123 --> "KEYCODE_MOVE_END"
The complete list of commands can be found on: http://developer.android.com/reference/android/view/KeyEvent.html

- 2,786
- 32
- 43

- 2,867
- 1
- 13
- 8
-
1This list is obviously longer for later Android versions, for example for 4.2.2 we can find them in [android.view.KeyEvent.java](http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.2.2_r1/android/view/KeyEvent.java?av=f), where they number up to 219. – not2qubit Mar 14 '15 at 20:45
-
-
In developer options, enable "Pointer location" to determine the correct coordinates when inputting touch events. – Dick Lucas Nov 18 '16 at 15:37
-
Just for extra information. Swipe only worked on my phone if the time was larger than 120!! ``adb shell input swipe 200 800 200 400 200`` – Hozeis Nov 16 '18 at 12:56
-
-
Hi @Rene Barbosa, I am working on module were i am recording all the touch event and after that i am playing those using tap and swipe command, tap is working fine but issue is with swipe command, we have to send millis at end but i am unable to calculate exact millisecond from x,y coordinate and swipe is not happening same as recorded. how can i calculate exact millisecond to send in end of swipe command? So it will work accurately while swipe. – amit semwal Apr 19 '21 at 07:51
-
Also, if you want to send embedded spaces with the input command, use %s
adb shell input text 'this%sis%san%sexample'
will yield
this is an example
being input.
%
itself does not need escaping - only the special %s
pair is treated specially. This leads of course to the obvious question of how to enter the literal string %s
, which you would have to do with two separate commands.

- 779
- 7
- 24

- 1,013
- 8
- 6
-
-
Here's a [simple bash script](https://stackoverflow.com/questions/3978299/typing-on-an-android-device-straight-from-computer/46751558#46751558) to take care of escaping, so you can just say `atext "Hey, I'm here"` and it works. – Dan Dascalescu Oct 15 '17 at 04:05
-
Do you know perhaps if it's possible to type unicode? Or is it only ascii? – android developer Nov 22 '21 at 21:15
I wrote a simple Powershell script for windows users to map keys to adb shell input events. And controll an Android device remotely over LAN. I don't know if anyone finds it usefull, but I'll share it anyways.
$ip = 192.168.1.8
cd D:\Android\android-sdk-windows\platform-tools\; .\adb.exe disconnect $ip; .\adb.exe connect $ip
$adbKeyNum = @{LeftWindows = "1"; F1 = "3"; Enter = "66"; UpArrow = "19"; DownArrow = "20"; LeftArrow = "21"; RightArrow = "22"; Add = "24";
Subtract = "25"; Backspace = "4"; P = "26"}
while(1 -eq 1){
$keyPress = [Console]::ReadKey($true).Key
if ([string]$keyPress -eq "F10"){
.\adb.exe disconnect $ip
exit
}
elseif ([string]$keyPress -eq "F6"){
$string = Read-Host -Prompt 'Input the string: '
.\adb.exe shell input text $string
}
elseif ($adbKeyNum.ContainsKey([string]$keyPress)){
echo $adbKeyNum.Get_Item([string]$keyPress)
.\adb.exe shell input keyevent $adbKeyNum.Get_Item([string]$keyPress)
}
}

- 281
- 4
- 6
One other difference:
- "adb shell input" is calling the input.jar to process and send the keycode from the Java layer of the android framework.
- "adb sendevent" is actually c code (part of toolbox utility ) that sends the input code directly into the /dev/input.... of Linux input subsystem.
More detail code trace into inside AOSP Framework can be found here:
http://www.srcmap.org/sd_share/4/aba57bc6/AOSP_adb_shell_input_Code_Trace.html#RefId=7c8f5285

- 189
- 1
- 6
-
-
This answers the OP question; this is the direct answer to the question as it stands. – Zimba Jul 23 '21 at 07:41
By the way, if you are trying to find a way to send double quotes to the device, try the following:
adb shell input text '\"'
I'm not sure why there's no event code for quotes, but this workaround does the job. Also, if you're using MonkeyDevice (or ChimpChat) you should test each caracter before invoking monkeyDevice.type, otherwise you get nothing when you try to send "

- 121
- 1
- 2
-
1I've made a [simple bash script](https://stackoverflow.com/questions/3978299/typing-on-an-android-device-straight-from-computer/46751558#46751558) to take care of all the escaping, so you can just say `atext "Hey, I'm here"` and it works. – Dan Dascalescu Oct 15 '17 at 04:05
If you want to send a text to specific device when multiple devices connected. First look for the attached devices using adb devices
adb devices
List of devices attached
3004e25a57192200 device
31002d9e592b7300 device
then get your specific device id and try the following
adb -s 31002d9e592b7300 shell input text 'your%stext'

- 4,030
- 3
- 25
- 60

- 559
- 5
- 9
To send a reload call to a React-Native app running in a android device: adb shell input keyboard text "rr"

- 316
- 2
- 6