亚行壳牌input事件

adb shell input keyeventadb shell sendevent之间的基本区别是什么? 我应该用哪一个来input一个字符? 我们传递给这两个命令的键码是否相同?

通过adb shell input keyeventevent_codestring将被发送到设备。

 usage: input [text|keyevent] input text <string> input keyevent <event_code> 

event_code一些可能的值是:

 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" 

sendevent实用程序发送触摸或键盘事件,以及其他事件来模拟硬件事件。 有关详细信息请参阅此文章: Android,低级别的shell在屏幕上单击

更新:

使用adb shell input

插入文字:

 adb shell input text "insert%syour%stext%shere" 

(obs:%s表示空格)

..

事件代码:

 adb shell input keyevent 82 

(82 —> MENU_BUTTON)

“有关更多关键事件代码,请参阅下面的列表”

..

点击X,Y位置:

 adb shell input tap 500 1450 

要find想要点击的确切X,Y位置,请转到:

设置>开发人员选项>检查选项POINTER SLOCATION

..

滑动X1 Y1 X2 Y2 [持续时间(ms)]:

 adb shell input swipe 100 500 100 1450 100 

在这个例子中,X1 = 100,Y1 = 500,X2 = 100,Y2 = 1450,持续时间= 100ms

..

LongPress XY:

 adb shell input swipe 100 500 100 500 250 

我们使用相同的命令来模拟长按

在这个例子中,X = 100,Y = 500,持续时间= 250ms

..

事件代码更新列表:

 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" 

完整的命令列表可以在http://developer.android.com/reference/android/view/KeyEvent.html上find。;

另外,如果要使用input命令发送embedded的空格,请使用%s

 adb shell input text 'this%sis%san%sexample' 

会屈服

 this is an example 

被input。

%本身不需要转义 – 只有特殊的%s对被专门处理。 这当然会导致如何inputstring%s …这个明显的问题,你必须使用两个单独的命令。

顺便说一下,如果您试图find一种方法发送双引号到设备,请尝试以下操作:

adb shellinput文字'\''

我不知道为什么没有事件代码引用,但是这个解决方法做的工作。 另外,如果你使用MonkeyDevice(或者ChimpChat),你应该在调用monkeyDevice.type之前testing每个caracter,否则当你尝试发送“

另一个区别是:

  • adb shell input ”正在调用input.jar来处理和发送android框架的Java层的keycode。
  • adb sendevent ”实际上是将input代码直接发送到Linuxinput子系统的/ dev / input ….中的c代码(工具箱实用程序的一部分)。

AOSP框架内的更多详细代码追踪可以在这里find:

http://www.srcmap.org/sd_share/4/aba57bc6/AOSP_adb_shell_input_Code_Trace.html#RefId=7c8f5285

我为Windows用户编写了一个简单的Powershell脚本,将键映射到adb shellinput事件。 并通过局域网远程控制Android设备。 我不知道是否有人发现它有用,但我会分享它。

 $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) } }