adbにはAndroid上で操作したイベントをリアルタイムで表示する機能があります。
adb devices
![](https://lil.la/wp-content/uploads/image-520.png)
adb -s 127.0.0.1:62001 shell getevent
![](https://lil.la/wp-content/uploads/image-521.png)
今回は上のスクリーンショットにある、 127.0.0.1:62001 で認識されるAndroidを自動操作します。
Android_Inputのすぐ上の緑枠のイベント番号が後で必要になるので覚えておきます。
別PCでのAndoroid端末認識例
![](https://lil.la/wp-content/uploads/image-388.png)
出力例
![](https://lil.la/wp-content/uploads/image-390.png)
getevent に-tlオプションを付けると少し見やすく表示されます
![](https://lil.la/wp-content/uploads/image-392-585x371.png)
adb shell getevent -tl の出力をさらに見やすくタップイベントのみ表示させるスクリプト
以下のAwkスクリプトを使用します。
AWKやSLEEPコマンドが必要ですので、ない人は BusyBoxを使えるようにしてください。
使い方
adb -s 127.0.0.1:62025 shell getevent -tl /dev/input/event4 | awk -f eventproc.awk
実行の様子
![](https://lil.la/wp-content/uploads/image-393-585x205.png)
この出力をバッチファイルとしてリダイレクトをすることで記録、再生が可能です。
adb -s 127.0.0.1:62025 shell getevent -tl /dev/input/event4 | awk -f eventproc.awk > hogehoge.bat
![](https://lil.la/wp-content/uploads/image-394-585x478.png)
カスタマイズ
eventproc.awk の冒頭を見ると設定項目があります
# adb -s 127.0.0.1:62025 shell getevent -tl /dev/input/event4 | busybox awk -f eventproc.awk
BEGIN {
ADB_NAME = "adb"
ADB_DEVICE = "-s 127.0.0.1:62025"
COMMAND_TAP = "shell input touchscreen tap"
COMMAND_SLEEP = "sleep"
UpTime = ""
}
ADB_NAME
adbやnox_adb
ADB_DEVICE\
adv devices で表示されたデバイス名
COMMAND_TAP
adbでタップするときのコマンド。
これを書き換えることはないでしょう。
COMMAND_SLEEP
sleepコマンドがない場合 TimeOut に書き換えると良いでしょう
謝辞
AWKスクリプト内で16進数→10進数を変換するため、以下のサイトのhex2decimalを丸パク(ry 参考にさせていただきました。
16進10進変換でAWK内部を窺う
http://awkytalky.jugem.jp/?eid=5
コメント