跳到主要内容

输入信息 (Node.input)

Node.input

声明

node:input(msg)

参数

参数类型是否必填说明
msgstring输入的信息,空字符串表示清空输入框(默认)

返回值

类型说明
boolean输入成功返回 true,失败返回 false

说明

向指定控件输入文本内容。

工作原理:

  • 通过 Android AccessibilityService 的 performAction(ACTION_SET_TEXT) 实现
  • 直接设置控件的文本内容,不模拟键盘输入
  • 输入速度极快,适合大量文本输入

适用场景:

  • 填写表单(用户名、密码、搜索框等)
  • 编辑文本内容
  • 清空输入框(传入空字符串)

注意事项:

  • 控件必须是可编辑类型(如 EditText),且 editable=true
  • 此方法会替换控件中的全部文本,而非追加
  • 某些应用的输入框可能有输入监听,直接设置文本可能绕过验证逻辑
  • 如需模拟真实键盘输入(触发输入事件),请使用 key 模块

与 selector:input() 的区别:

  • n:input() 是对已找到的控件直接输入
  • selector:input() 是查找并输入的组合操作(动作约束)
待实现

该接口正在开发中。

示例

local node = require("node")

local n = node.selector():id("com.example:id/search_bar_text"):type("EditText"):find()
if n then
n:input("自在老师讲的不错")
end

-- 清空输入框
if n then
n:input("")
end

AScript 对应

# AScript (Python)
from ascript.android.node import Selector

node = Selector().id("com.aojoy.airscript:id/search_bar_text").type("EditText").find()
if node:
node.input("自在老师讲的不错")