当前位置:网站首页>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);
}
});总结
记住即可,以上都是常用的事件处理,每天学习一点点哈嘻。
光看不敲是没用的
看后一定要去实践
一定要去敲代码
一定要去运行试错
这样才是有意义的学习
边栏推荐
- [machine learning notes] univariate linear regression principle, formula and code implementation
- 【经验】win11上安装visio
- 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
- 巨杉数据库再次亮相金交会,共建数字经济新时代
- Installation de la Bibliothèque de processus PDK - csmc
- nacos-高可用seata之TC搭建(02)
- 04. 项目博客之日志
- Pickle and savez_ Compressed compressed volume comparison
- SQLite add index
- Quantitative description of ANC noise reduction
猜你喜欢

Talking about the type and function of lens filter

Self built DNS server, the client opens the web page slowly, the solution
![[leetcode] 18. Sum of four numbers](/img/06/c160b47d756290e5474e4c07e68648.png)
[leetcode] 18. Sum of four numbers

浅谈镜头滤镜的类型及作用

巨杉数据库再次亮相金交会,共建数字经济新时代
![[effective Objective-C] - memory management](/img/1e/611aa998486bbac76ac103c3091794.jpg)
[effective Objective-C] - memory management

Pointer classic written test questions

Excel转换为Lua的配置文件

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

Vulhub vulnerability recurrence 71_ Unomi
随机推荐
JDBC calls the stored procedure with call and reports an error
Game push: image / table /cv/nlp, multi-threaded start!
Vulhub vulnerability recurrence 69_ Tiki Wiki
In 2022, we must enter the big factory as soon as possible
Vulhub vulnerability recurrence 73_ Webmin
指针经典笔试题
Cuda11.1 online installation
Summary of deep learning tuning tricks
趋势前沿 | 达摩院语音 AI 最新技术大全
Force buckle 1189 Maximum number of "balloons"
LeetCode_ String inversion_ Simple_ 557. Reverse word III in string
JS array list actual use summary
pix2pix:使用条件对抗网络的图像到图像转换
February 12 relativelayout
Talking about the type and function of lens filter
Detailed summary of SQL injection
UCF (2022 summer team competition I)
C AES encrypts strings
SequoiaDB湖仓一体分布式数据库2022.6月刊
【经验】win11上安装visio