当前位置:网站首页>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);
}
});总结
记住即可,以上都是常用的事件处理,每天学习一点点哈嘻。
光看不敲是没用的
看后一定要去实践
一定要去敲代码
一定要去运行试错
这样才是有意义的学习
边栏推荐
- Nacos - TC Construction of High available seata (02)
- Check the useful photo lossless magnification software on Apple computer
- Codeless June event 2022 codeless Explorer conference will be held soon; AI enhanced codeless tool launched
- 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
- 27io stream, byte output stream, OutputStream writes data to file
- How to use PHP string query function
- 指針經典筆試題
- 【torch】|torch. nn. utils. clip_ grad_ norm_
- 04. 项目博客之日志
- C Advanced - data storage (Part 1)
猜你喜欢

无代码六月大事件|2022无代码探索者大会即将召开;AI增强型无代码工具推出...

Summary of deep learning tuning tricks

01. Project introduction of blog development project

CUDA11.1在线安装

ByteDance program yuan teaches you how to brush algorithm questions: I'm not afraid of the interviewer tearing the code

Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist

Configuration file converted from Excel to Lua

Promise summary

F12 solve the problem that web pages cannot be copied
![[leetcode16] the sum of the nearest three numbers (double pointer)](/img/99/a167b0fe2962dd0b5fccd2d9280052.jpg)
[leetcode16] the sum of the nearest three numbers (double pointer)
随机推荐
04. 项目博客之日志
UCF (2022 summer team competition I)
Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist
Vulhub vulnerability recurrence 71_ Unomi
Pointer classic written test questions
Selective parameters in MATLAB functions
Game push: image / table /cv/nlp, multi-threaded start!
剑指 Offer II 039. 直方图最大矩形面积
[detailed explanation of Huawei machine test] statistics of shooting competition results
03. 开发博客项目之登录
[leetcode16] the sum of the nearest three numbers (double pointer)
【华为机试真题详解】检查是否存在满足条件的数字组合
Closure, decorator
nacos-高可用seata之TC搭建(02)
Knowledge points of circular structure
How to use PHP string query function
指针经典笔试题
备忘一下jvxetable的各种数据集获取方法
Configuration file converted from Excel to Lua
指針經典筆試題