1 界面效果图
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/ae2658991928121bee0d424be0649cad.png)
"ui";
ui.layout(
<vertical>
<appbar>
<toolbar title="LongClick" />
</appbar>
<Switch id="autoService" text="无障碍服务" checked="{{auto.service != null}}" padding="8 8 8 8" textSize="15sp" />
<frame height="30" gravity="center">
<text text="version:v.1.0" gravity="center" />
</frame>
<vertical padding="15">
<text textSize="15sp" textColor="black" text="请输入点击次数[0=不限]:" />
<input id="ClickNumber" text="0" />
</vertical>
<vertical padding="15">
<text textSize="15sp" textColor="black" text="请输入点击坐标X:" />
<input id="ClickintX" text="640" />
</vertical>
<vertical padding="15">
<text textSize="15sp" textColor="black" text="请输入点击坐标Y:" />
<input id="ClickintY" text="270" />
</vertical>
<vertical padding="15">
<text textSize="15sp" textColor="black" text="请输入点击间隔[毫秒]:" />
<input id="ClickSleep" text="10" />
</vertical>
<button id="save" text="保存配置" />
<button id="start" text="开始运行" />
</vertical>
);
ui.autoService.on("check", function (checked) {
if (checked && auto.service == null) {
app.startActivity({
action: "android.settings.ACCESSIBILITY_SETTINGS"
});
}
if (!checked && auto.service != null) {
auto.service.disableSelf();
}
});
ui.emitter.on("resume", function () {
ui.autoService.checked = auto.service != null;
});
ui.save.on("click", function () {
threads.start(function () {
var Set_ClickNumber = ui.ClickNumber.text();
var Set_ClickintX = ui.ClickintX.text();
var Set_ClickintY = ui.ClickintY.text();
var Set_ClickSleep = ui.ClickSleep.text();
pz.put("Set_ClickNumber", Set_ClickNumber)
pz.put("Set_ClickintX", Set_ClickintX)
pz.put("Set_ClickintY", Set_ClickintY)
pz.put("Set_ClickSleep", Set_ClickSleep)
toast("配置保存成功")
sleep(2000)
});
}
);
var pz = storages.create("pz")
var Get_Set_ClickNumber = pz.get("Set_ClickNumber")
if (Get_Set_ClickNumber) {
ui.ClickNumber.setText(Get_Set_ClickNumber)
}
var Get_Set_ClickintX = pz.get("Set_ClickintX")
if (Get_Set_ClickintX) {
ui.ClickintX.setText(Get_Set_ClickintX)
}
var Get_Set_ClickintY = pz.get("Set_ClickintY")
if (Get_Set_ClickintY) {
ui.ClickintY.setText(Get_Set_ClickintY)
}
var Get_Set_ClickSleep = pz.get("Set_ClickSleep")
if (Get_Set_ClickNumber) {
ui.ClickSleep.setText(Get_Set_ClickSleep)
}
ui.start.on("click", function () {
var Set_ClickNumber = ui.ClickNumber.text();
var Set_ClickintX = ui.ClickintX.text();
var Set_ClickintY = ui.ClickintY.text();
var Set_ClickSleep = ui.ClickSleep.text();
pz.put("Set_ClickNumber", Set_ClickNumber)
pz.put("Set_ClickintX", Set_ClickintX)
pz.put("Set_ClickintY", Set_ClickintY)
pz.put("Set_ClickSleep", Set_ClickSleep)
events.observeKey();
events.onKeyDown("volume_up", function (event) {
toastLog("终止运行");
exit();
});
events.on("exit", function () {
toastLog("终止运行");
console.hide();
threads.shutDownAll()
});
threads.start(function () {
main()
})
})
function main() {
var Set_ClickNumber = Number(ui.ClickNumber.text());
var Set_ClickintX = Number(ui.ClickintX.text());
var Set_ClickintY = Number(ui.ClickintY.text());
var Set_ClickSleep = Number(ui.ClickSleep.text());
var GuNumber = 0
for (var a = 0; a < 20; a++) {
toastLog("温馨提示: " + a + " / 20 秒后开始运行")
sleep(1000)
}
if (Set_ClickNumber == 0) {
while (true) {
click(Set_ClickintX, Set_ClickintY)
GuNumber = GuNumber + 1
toastLog("工作: " + GuNumber)
sleep(Set_ClickSleep)
}
}
else {
for (var n = 0; n < Set_ClickNumber; n++) {
click(Set_ClickintX, Set_ClickintY)
GuNumber = GuNumber + 1
toastLog("工作: " + GuNumber)
sleep(Set_ClickSleep)
}
}
}