当前位置:网站首页>Auto.js学习笔记17:基础监听事件和UI简单的点击事件操作
Auto.js学习笔记17:基础监听事件和UI简单的点击事件操作
2022-07-06 05:32:00 【PYB3】
目录
申明本人使用的autojs是4.1.1版本
events
启用按键监听,例如音量键、Home键。按键监听使用无障碍服务实现,如果无障碍服务未启用会抛出异常并提示开启。
只有这个函数成功执行后, onKeyDown
, onKeyUp
等按键事件的监听才有效。
该函数在安卓4.3以上才能使用。
相关参数
keys.home 主页键
keys.back 返回键
keys.menu 菜单键
keys.volume_up 音量上键
keys.volume_down 音量下键
代码示例
//启用按键监听
events.observeKey();
//监听音量上键按下
events.onKeyDown("volume_up", function(event){
toast("音量上");
unregisterReceiver();
});
//监听音量下键弹起
events.onKeyDown("volume_down", function(event){
toast("音量下");
});
//监听Home键弹起
events.onKeyDown("home", function(event){
toast("Home");
});
//监听菜单键按下
events.onKeyDown("menu", function(event){
toast("菜单键被按下了");
});
注册触摸事件
- listener {Function} 参数为Point的函数
注册一个触摸监听函数。相当于on("touch", listener)
。
events.observeTouch();
//注册触摸监听器
events.onTouch(function(s){
//触摸事件发生会打印出触摸的坐标
log(s.x + ", " + s.y);
});
删除所有事件监听函数
events.removeAllTouchListeners()
按钮点击事件
Switch
ui局部代码
<vertical id = "setConfigView" w = "*" h = "auto" layout_centerInParent="true" >
<Switch id = "openSwh" w = "auto" h = "auto" textStyle = "bold" textColor = "red"
text = "无障碍权限 " textSize="16sp" marginBottom = "15" marginRight ="10"/>
</vertical>
点击事件代码
//按钮监听方式
ui.openSwh.on("check", function(checked) {
// 用户勾选无障碍服务的选项时,跳转到页面让用户去开启
if(checked && auto.service == null) {
app.startActivity({
action: "android.settings.ACCESSIBILITY_SETTINGS"
});
exit();
}
if(!checked && auto.service != null){
auto.service.disableSelf(); //关闭无障碍服务
ui.openSwh.setChecked(false);
}
});
button
ui局部代码
<button id = "testServerAPI" align="center">测试接口数据</button>
点击事件代码
ui.testServerAPI.click(()=>{
testAPIState = true;
getServiceInfo();
});
timepicker
ui代码
<text id = "timePickerModeText" text = "滑动时间选择:" textColor = "black" textSize="16sp" marginTop="5" />
<timepicker id = "timePickerMode" timePickerMode="spinner" />
监听事件代码
//滑动时间选择
ui.timePickerMode.setIs24HourView(true);//设置当前时间控件为24小时制
ui.timePickerMode.setHour(9); //设置当前小时
ui.timePickerMode.setMinute(0); //设置当前分(0-59)
ui.timePickerMode.setOnTimeChangedListener({
onTimeChanged: function (v, h, m) {
//h 获取的值 为24小时格式
wxAutoConfigObj.timingTime = h + ":" + m ;
ui.timePickerModeText.setText("滑动时间选择: " + wxAutoConfigObj.timingTime);
}
});
总结
记住即可,以上都是常用的事件处理,每天学习一点点哈嘻。
光看不敲是没用的
看后一定要去实践
一定要去敲代码
一定要去运行试错
这样才是有意义的学习
边栏推荐
- UCF(暑期团队赛二)
- February 12 relativelayout
- 巨杉数据库再次亮相金交会,共建数字经济新时代
- SQLite queries the maximum value and returns the whole row of data
- Pix2pix: image to image conversion using conditional countermeasure networks
- Easy to understand IIC protocol explanation
- MySQL advanced learning summary 9: create index, delete index, descending index, and hide index
- jdbc使用call调用存储过程报错
- Vulhub vulnerability recurrence 68_ ThinkPHP
- Self built DNS server, the client opens the web page slowly, the solution
猜你喜欢
[effective Objective-C] - memory management
Summary of redis basic knowledge points
Modbus protocol communication exception
Codeforces Round #804 (Div. 2) Editorial(A-B)
PDK process library installation -csmc
Self built DNS server, the client opens the web page slowly, the solution
Deep learning -yolov5 introduction to actual combat click data set training
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Check the useful photo lossless magnification software on Apple computer
Fluent implements a loadingbutton with loading animation
随机推荐
01. Project introduction of blog development project
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
UCF (2022 summer team competition I)
How to use PHP string query function
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Pix2pix: image to image conversion using conditional countermeasure networks
Qt TCP 分包粘包的解决方法
Huawei equipment is configured with OSPF and BFD linkage
Huawei od computer test question 2
C Advanced - data storage (Part 1)
05. 博客项目之安全
Fluent implements a loadingbutton with loading animation
Web Security (V) what is a session? Why do I need a session?
Select knowledge points of structure
Mysql高级篇学习总结9:创建索引、删除索引、降序索引、隐藏索引
[leetcode16] the sum of the nearest three numbers (double pointer)
Game push: image / table /cv/nlp, multi-threaded start!
用StopWatch 统计代码耗时
【LeetCode】18、四数之和
指针经典笔试题