前言
简单介绍了 Android 平台 Input 命令模拟按键,并写了个脚本应用在手机上,在模拟器上玩恶魔城月轮用大骨头自动刷怪升级。。。
介绍
Usage: input [<source>] <command> [<arg>...]
The sources are:
keyboard
mouse
joystick
touchnavigation
touchpad
trackball
dpad
stylus
gamepad
touchscreen
The commands and default sources are:
text <string> (Default: touchscreen)
keyevent [--longpress] <key code number or name> ... (Default: keyboard)
tap <x> <y> (Default: touchscreen)
swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)
press (Default: trackball)
roll <dx> <dy> (Default: trackball)
注:可以用来模拟长按,在 input swipe 未完成前退出,这样就只有按下事件,没有松开事件,就一直长按?
#adb shell "input swipe 110 520 110 520 1000" # 滑动操作,未结束前退出,就是长按
adb shell input tap 100 100 # 点击操作
adb shell input keyevent 4 # 按键操作
模拟长按:
#!/bin/sh
while true
do
# 注,实现功能后就退出,这样就能实现长按了
adb shell "input swipe 1200 520 1200 520 10000"
sleep 1
done
使用
就是先通过开发者选项知道模拟键位置,然后通过 input 模拟, 左–>发招 --> 右 —> 左 的循环操作。。。
#!/bin/sh
#################################################
# x y
# 左: 121 539
# 右: 295 534
# B: 1166 559
#adb shell "input swipe 110 520 110 520 10"
# 点1 点2 时长
#################################################
while true
do
# 注,实现功能后就退出,这样能实现长按
# 左
#adb shell "input swipe 121 539 121 539 10"
adb shell input tap 121 539
# B
adb shell input tap 1166 559
adb shell input tap 1166 559
adb shell input tap 1166 559
# 睡眠以防止升级未完成转身
sleep 1
#adb shell "input swipe 1166 559 1166 559 1"
#adb shell "input swipe 1166 559 1166 559 1"
#adb shell "input swipe 1166 559 1166 559 1"
#adb shell "input swipe 1166 559 1166 559 1"
#adb shell "input swipe 1166 559 1166 559 1"
#adb shell "input swipe 1166 559 1166 559 1"
#adb shell "input swipe 1166 559 1166 559 1"
#adb shell "input swipe 1166 559 1166 559 1"
# 右
#adb shell "input swipe 295 534 295 534 10"
adb shell input tap 295 534
#sleep 0.1
done