Android Input 介绍及使用

本文介绍如何使用Android平台的Input命令模拟按键输入,通过编写Shell脚本来实现游戏自动化操作,如在恶魔城月轮中自动刷怪升级。文章详细解释了Input命令的使用方法,包括模拟键盘、鼠标、触摸屏等输入设备的指令,以及如何实现长按、循环操作等高级功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

简单介绍了 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值