跳到主要内容

Keyboard:cursor()

将文本光标移动到获得焦点的文本字段中的某个字符位置。

签名​

Keyboard:cursor(position: number): void

参数​

参数类型描述
positionnumber从字段开头算起的字符偏移量;0 表示第一个字符之前

返回值

void

描述​

位置会被限制在当前文本长度范围内。光标定位需要 Accessibility 模式;在 Native (root) 模式下,该调用会抛出异常,因为 shell 无法可靠地放置光标。

示例​

Keyboard:type("Hello world")
Keyboard:cursor(5) -- before the space
Keyboard:type(" there") -- "Hello there world"

兼容版本:1.0.0.37 及以上