当前位置:网站首页>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);
}
});总结
记住即可,以上都是常用的事件处理,每天学习一点点哈嘻。
光看不敲是没用的
看后一定要去实践
一定要去敲代码
一定要去运行试错
这样才是有意义的学习
边栏推荐
- Codeless June event 2022 codeless Explorer conference will be held soon; AI enhanced codeless tool launched
- LeetCode_ String inversion_ Simple_ 557. Reverse word III in string
- Application Security Series 37: log injection
- Problems encountered in installing mysql8 on MAC
- Detailed summary of SQL injection
- Nacos TC setup of highly available Seata (02)
- Solution of QT TCP packet sticking
- [effective Objective-C] - memory management
- Knowledge points of circular structure
- MySQL advanced learning summary 9: create index, delete index, descending index, and hide index
猜你喜欢

How to use PHP string query function

Unity Vector3. Use and calculation principle of reflect

趋势前沿 | 达摩院语音 AI 最新技术大全

【云原生】3.1 Kubernetes平台安装KubeSpher

nacos-高可用seata之TC搭建(02)

Check the useful photo lossless magnification software on Apple computer

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

01. 开发博客项目之项目介绍

Vulhub vulnerability recurrence 73_ Webmin
随机推荐
Questions d'examen écrit classiques du pointeur
03. Login of development blog project
算法-- 爬楼梯(Kotlin)
RustDesk 搭建一个自己的远程桌面中继服务器
2022半年总结
[leetcode] 18. Sum of four numbers
Detailed summary of SQL injection
Algorithm -- climbing stairs (kotlin)
Imperial cms7.5 imitation "D9 download station" software application download website source code
Summary of redis basic knowledge points
After the project is released, index Html is cached
ByteDance program yuan teaches you how to brush algorithm questions: I'm not afraid of the interviewer tearing the code
05. Security of blog project
Check the useful photo lossless magnification software on Apple computer
Selective parameters in MATLAB functions
Pointer classic written test questions
Promise summary
[QNX Hypervisor 2.2用户手册]6.3.3 使用共享内存(shmem)虚拟设备
Summary of deep learning tuning tricks
MySQL advanced learning summary 9: create index, delete index, descending index, and hide index