当前位置:网站首页>Auto. JS learning notes 17: basic listening events and UI simple click event operations
Auto. JS learning notes 17: basic listening events and UI simple click event operations
2022-07-06 05:42:00 【PYB3】
Catalog
Delete all event listening functions
Declare that I use autojs yes 4.1.1 edition
events
Enable key listening , For example, volume keys 、Home key . Key monitoring is realized by using barrier free services , If the barrier free service is not enabled, an exception will be thrown and a prompt to start .
Only after this function is successfully executed , onKeyDown
, onKeyUp
Wait for key event monitoring to be effective .
This function is available on Android 4.3 The above can be used .
Related parameters
keys.home Home key
keys.back Return key
keys.menu Menu key
keys.volume_up Volume up button
keys.volume_down Voice Down
Code example
// Enable key listening
events.observeKey();
// Monitor volume up key press
events.onKeyDown("volume_up", function(event){
toast(" Volume up ");
unregisterReceiver();
});
// Monitor the volume and press the button to pop up
events.onKeyDown("volume_down", function(event){
toast(" Volume down ");
});
// monitor Home The key bounces
events.onKeyDown("home", function(event){
toast("Home");
});
// Press the monitor menu key
events.onKeyDown("menu", function(event){
toast(" The menu key is pressed ");
});
Register touch events
- listener {Function} Parameter is Point Function of
Register a touch monitoring function . amount to on("touch", listener)
.
events.observeTouch();
// Register a touch monitor
events.onTouch(function(s){
// When a touch event occurs, the coordinates of the touch will be printed
log(s.x + ", " + s.y);
});
Delete all event listening functions
events.removeAllTouchListeners()
Button click event
Switch
ui Local code
<vertical id = "setConfigView" w = "*" h = "auto" layout_centerInParent="true" >
<Switch id = "openSwh" w = "auto" h = "auto" textStyle = "bold" textColor = "red"
text = " Accessibility " textSize="16sp" marginBottom = "15" marginRight ="10"/>
</vertical>
Click on the event code
// Button monitoring mode
ui.openSwh.on("check", function(checked) {
// When users check the accessibility option , Jump to the page and let the user open it
if(checked && auto.service == null) {
app.startActivity({
action: "android.settings.ACCESSIBILITY_SETTINGS"
});
exit();
}
if(!checked && auto.service != null){
auto.service.disableSelf(); // Turn off accessibility services
ui.openSwh.setChecked(false);
}
});
button
ui Local code
<button id = "testServerAPI" align="center"> Test interface data </button>
Click on the event code
ui.testServerAPI.click(()=>{
testAPIState = true;
getServiceInfo();
});
timepicker
ui Code
<text id = "timePickerModeText" text = " Sliding time selection :" textColor = "black" textSize="16sp" marginTop="5" />
<timepicker id = "timePickerMode" timePickerMode="spinner" />
Listen for event code
// Sliding time selection
ui.timePickerMode.setIs24HourView(true);// Set the current time control to 24 hourly
ui.timePickerMode.setHour(9); // Set the current hour
ui.timePickerMode.setMinute(0); // Set current score (0-59)
ui.timePickerMode.setOnTimeChangedListener({
onTimeChanged: function (v, h, m) {
//h Get the value of by 24 Hour format
wxAutoConfigObj.timingTime = h + ":" + m ;
ui.timePickerModeText.setText(" Sliding time selection : " + wxAutoConfigObj.timingTime);
}
});
summary
Just remember , The above are common event handling , Learn a little hip-hop every day .
It's no use just looking without knocking
After reading, we must practice
Be sure to type the code
Be sure to run trial and error
This is meaningful learning
边栏推荐
- B站刘二大人-多元逻辑回归 Lecture 7
- 【云原生】3.1 Kubernetes平台安装KubeSpher
- The digital economy has broken through the waves. Is Ltd a Web3.0 website with independent rights and interests?
- Questions d'examen écrit classiques du pointeur
- B站刘二大人-Softmx分类器及MNIST实现-Lecture 9
- 02. Develop data storage of blog project
- 05. 博客项目之安全
- 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
- Closure, decorator
- 清除浮动的方式
猜你喜欢
Sequoiadb Lake warehouse integrated distributed database, June 2022 issue
Application Security Series 37: log injection
Vulhub vulnerability recurrence 69_ Tiki Wiki
初识数据库
P2802 回家
【torch】|torch.nn.utils.clip_grad_norm_
Codeforces Round #804 (Div. 2) Editorial(A-B)
【经验】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
Pointer classic written test questions
随机推荐
毕业设计游戏商城
P2802 回家
PDK工艺库安装-CSMC
[string] palindrome string of codeup
B站刘二大人-线性回归及梯度下降
Text classification still stays at Bert? The dual contrast learning framework is too strong
How can large websites choose better virtual machine service providers?
初识数据库
Vulhub vulnerability recurrence 68_ ThinkPHP
ArcGIS application foundation 4 thematic map making
SQLite queries the maximum value and returns the whole row of data
HAC cluster modifying administrator user password
Sequoiadb Lake warehouse integrated distributed database, June 2022 issue
Node 之 nvm 下载、安装、使用,以及node 、nrm 的相关使用
Vulhub vulnerability recurrence 71_ Unomi
[detailed explanation of Huawei machine test] check whether there is a digital combination that meets the conditions
SQLite add index
PDK process library installation -csmc
【经验】win11上安装visio
Graduation design game mall