1. 程式人生 > >模擬鍵盤輸入adb shell input

模擬鍵盤輸入adb shell input

一、input text

1.作用:向聚焦的文字框中輸入內容,只能輸入AscII碼的字元,對於UTF-8的字元是無法輸入的(無法輸入中文)

用法:adb shell input text  " <String>"

在text後的雙引號中輸入字串

例如:向文字框中輸入內容 :hello,world

命令:adb shell input text "hello,world"


執行結果:


2.輸入特殊字元

用法:需要加一個轉義符\

命令:adb shell input text "\&"


執行後的結果;


二、input tap

作用:點選螢幕上的座標

用法:adb shell input tap <int> <int>

tap後輸入位置的座標

例如:點選螢幕上座標為500,500的點

命令:adb shell input tap 500 500


執行結果:

原來的介面:


執行後的介面:


三、input swipe

作用:在螢幕上滑動

用法:adb shell swipe <int> <int> <int> <int>

例如:點選螢幕上座標為500,500的點

命令:adb shell input tap 500 500


四、input keyevent

input keyevent 後加code值

命令格式adb shell input keyevent “value”


1.adb shell input keyevent 4

作用:按返回鍵

命令:adb shell input keyevent 4


執行結果:

原來的介面:


命令執行後:

返回到了主介面


2.adb shell input keyevent 3

作用:按home鍵

命令:adb shell input keyevent 3

執行結果:

原來的介面:


執行命令後的介面:


五、傳送滑鼠事件(Touch)

命令格式:adb shell sendevent [device] [type] [code] [value]

情況1:在某座標點上touch

如在螢幕的x座標為40

y座標為210的點上touch一下,命令如下

adb shell sendevent /dev/input/event0 3 0 40

adb shell sendevent /dev/input/event0 3 1 210

adb shell sendevent /dev/input/event0 1 330 1 //touch

adb shell sendevent /dev/input/event0 0 0 0//it must have

adb shell sendevent /dev/input/event0 1 330 0 //untouch

adb shell sendevent /dev/input/event0 0 0 0 //it must have

注:以上六組命令必須配合使用,缺一不可

情況2:模擬滑動軌跡(可下載並採用aPaint軟體進行試驗)

如下例是在aPaint軟體上畫出一條開始於(100,200),止於(108,200)的水平直線

adb shell sendevent /dev/input/event0 3 0 100 //start from point (100,200)

adb shell sendevent /dev/input/event0 3 1 200

adb shell sendevent /dev/input/event0 1 330 1 //touch

adb shell sendevent /dev/input/event0 0 0 0

adb shell sendevent /dev/input/event0 3 0 101 //step to point (101,200)

adb shell sendevent /dev/input/event0 0 0 0

……………………//must list each step, here just skip

adb shell sendevent /dev/input/event0 3 0 108 //end point(108,200)

adb shell sendevent /dev/input/event0 0 0 0

adb shell sendevent /dev/input/event0 1 330 0 //untouch

adb shell sendevent /dev/input/event0 0 0 0

注:參考資料:

http://smilejay.com/2014/12/adb-shell-input-chinese-character/

http://blog.sina.com.cn/s/blog_628b45090101qmm6.html

https://www.cnblogs.com/avonecho/p/3939160.html

http://blog.bihe0832.com/adb-shell-input.html

http://blog.csdn.net/slimboy123/article/details/54140029

http://blog.csdn.net/u011068616/article/details/47945927

http://blog.csdn.net/ekeuy/article/details/41038997

http://blog.bihe0832.com/adb-shell-input.html

https://sanjay-f.github.io/2015/11/24/Android%E6%B5%8B%E8%AF%95%E6%95%99%E7%A8%8B5--%E6%A8%A1%E6%8B%9F%E9%94%AE%E7%9B%98%E8%BE%93%E5%85%A5/

http://blog.csdn.net/huiguixian/article/details/8550170

http://blog.csdn.net/roger_ge/article/details/5552740

2.Android Keycode

KEYCODE_UNKNOWN=0;

KEYCODE_SOFT_LEFT=1;

KEYCODE_SOFT_RIGHT=2;

KEYCODE_HOME=3;

KEYCODE_BACK=4;

KEYCODE_CALL=5;

KEYCODE_ENDCALL=6;

KEYCODE_0=7;

KEYCODE_1=8;

KEYCODE_2=9;

KEYCODE_3=10;

KEYCODE_4=11;

KEYCODE_5=12;

KEYCODE_6=13;

KEYCODE_7=14;

KEYCODE_8=15;

KEYCODE_9=16;

KEYCODE_STAR=17;

KEYCODE_POUND=18;

KEYCODE_DPAD_UP=19;

KEYCODE_DPAD_DOWN=20;

KEYCODE_DPAD_LEFT=21;

KEYCODE_DPAD_RIGHT=22;

KEYCODE_DPAD_CENTER=23;

KEYCODE_VOLUME_UP=24;

KEYCODE_VOLUME_DOWN=25;

KEYCODE_POWER=26;

KEYCODE_CAMERA=27;

KEYCODE_CLEAR=28;

KEYCODE_A=29;

KEYCODE_B=30;

KEYCODE_C=31;

KEYCODE_D=32;

KEYCODE_E=33;

KEYCODE_F=34;

KEYCODE_G=35;

KEYCODE_H=36;

KEYCODE_I=37;

KEYCODE_J=38;

KEYCODE_K=39;

KEYCODE_L=40;

KEYCODE_M=41;

KEYCODE_N=42;

KEYCODE_O=43;

KEYCODE_P=44;

KEYCODE_Q=45;

KEYCODE_R=46;

KEYCODE_S=47;

KEYCODE_T=48;

KEYCODE_U=49;

KEYCODE_V=50;

KEYCODE_W=51;

KEYCODE_X=52;

KEYCODE_Y=53;

KEYCODE_Z=54;

KEYCODE_COMMA=55;

KEYCODE_PERIOD=56;

KEYCODE_ALT_LEFT=57;

KEYCODE_ALT_RIGHT=58;

KEYCODE_SHIFT_LEFT=59;

KEYCODE_SHIFT_RIGHT=60;

KEYCODE_TAB=61;

KEYCODE_SPACE=62;

KEYCODE_SYM=63;

KEYCODE_EXPLORER=64;

KEYCODE_ENVELOPE=65;

KEYCODE_ENTER=66;

KEYCODE_DEL=67;

KEYCODE_GRAVE=68;

KEYCODE_MINUS=69;

KEYCODE_EQUALS=70;

KEYCODE_LEFT_BRACKET=71;

KEYCODE_RIGHT_BRACKET=72;

KEYCODE_BACKSLASH=73;

KEYCODE_SEMICOLON=74;

KEYCODE_APOSTROPHE=75;

KEYCODE_SLASH=76;

KEYCODE_AT=77;

KEYCODE_NUM=78;

KEYCODE_HEADSETHOOK=79;

KEYCODE_FOCUS=80;//*Camera*focus

KEYCODE_PLUS=81;

KEYCODE_MENU=82;

KEYCODE_NOTIFICATION=83;

KEYCODE_SEARCH=84;

KEYCODE_MEDIA_PLAY_PAUSE=85;

KEYCODE_MEDIA_STOP=86;

KEYCODE_MEDIA_NEXT=87;

KEYCODE_MEDIA_PREVIOUS=88;

KEYCODE_MEDIA_REWIND=89;

KEYCODE_MEDIA_FAST_FORWARD=90;

KEYCODE_MUTE=91;

3.
4.
5.

6.