问题:安卓点击失效

在部分安卓应用程序中的 HTML5 页面中,出现脚本能够点击,但点击没有后续反应的问题。此问题目前可以通过以下写法来解决:

--其中 x,y 为坐标值 
os.execute("input mouse tap x y"),
--点击坐标(600,900)
x=100+500
y=500+400
m=tostring(x)
n=tostring(y)
os.execute("input mouse tap "..m.." "..n)

滑动,x1 y1 为滑动初始坐标,x2 y2 为滑动结束坐标

os.execute("input mouse swipe x1 y1 x2 y2")

如果以上命令还是不生效可以用下面的 API 方法代替 mouse 进行尝试:

keyboard  
joystick  
touchnavigation  
touchpad  
trackball  
stylus  
dpad  
touchscreen  
gamepad

示例代码

os.execute("input keyboard tap 100 100")

如果仍无法滑动可以使用 touchInputDown、touchInputMove、touchInputUp 函数。

函数:touchInputDown、touchInputMove、touchInputUp 触动点击、滑动(仅支持 Android)

函数名称:触摸按下、抬起、移动

函数功能:通过按下、抬起、移动动作发送触摸事件。

引擎版本:Android v3.1.0 及其以上

函数方法

touchInputDown(index,x ,y)

touchInputMove(index, x, y)

touchInputUp(index,x ,y)

返回值:无

参数 类型 必填 说明
index number 手指序号(可省略)
x number 屏幕横坐标
y number 屏幕纵坐标

函数用例

划动

--此示例代码所用函数为触动精灵专用函数请勿用于积木编程
--在部分安卓应用程序中的 HTML5 页面中,出现脚本能够点击,但点击没有后续反应的问题并且使用 os.execute 函数也没有效果,可以使用此函数
--在坐标 (150, 550)按下
touchInputDown(150, 550);    
mSleep(30);
--移动到坐标 (150, 600),注意一次滑动的坐标间隔不要太大,不宜超过 50 像素
touchInputMove(150, 600);    
mSleep(30);
--在坐标 (150, 600) 抬起
touchInputUp(150, 600);

注意事项

  • 需要注意的是在使用 touchInputDowntouchInputMovetouchInputUp 函数时,中间一定要插入一定的延时,建议大于 20 毫秒,否则可能会出现点击无效等异常情况。

  • 使用滑动函数时,新手常犯的错误就是两点之间滑动距离过大,请注意 touchInputDowntouchInputMove、 的坐标间隔不宜超过 50 像素。

  • 非多点触控可省略手指 id。

  • 此示例代码所用函数为触动精灵专用函数请勿用于积木编程。

Copyright 北京帮你玩科技有限公司 2023 all right reserved,powered by Gitbook该文章修订时间: 2024-03-06 17:50:18

results matching ""

    No results matching ""