refactor(module autojs): package com.stardust.autojs.runtime.inputevent

add: module engines
This commit is contained in:
hyb1996
2017-08-04 15:19:57 +08:00
parent f2c1015470
commit 19dac12614
37 changed files with 904 additions and 562 deletions

View File

@@ -32,6 +32,11 @@ launchApp("微信");
获取应用的包名。例如getPackageName("QQ")为"com.tencent.mobileqq"。如果有相同名称的应用,只返回其中某一个的包名。如果不存在这个名称的应用,会返回空字符串。
### getAppName(packageName)
* packageName \<String\> 应用包名
返回对应包名的应用的名称。如果应用不存在返回null。
### openAppSetting(packageName)
* packageName \<String\> 应用包名

View File

@@ -104,7 +104,9 @@ events.loop();
删除所有事件监听函数。
### key事件
### 事件: 'key'
* keyCode \<Number\> 键值
* event \<KeyEvent\> 事件
当有按键被按下或弹起时会触发该事件。
```
@@ -122,7 +124,9 @@ events.loop();
* KeyEvent.KEYCODE_VOLUME_UP 音量上键
* KeyEvent.KEYCODE_VOLUME_DOWN 音量下键
### key_down事件
### 事件: 'key_down'
* keyCode \<Number\> 键值
* event \<KeyEvent\> 事件
当有按键被按下时会触发该事件。
```
@@ -134,7 +138,9 @@ events.on("key_down", function(keyCode, event){
events.loop();
```
### key_up事件
### 事件: 'key_up'
* keyCode \<Number\> 键值
* event \<KeyEvent\> 事件
当有按键弹起时会触发该事件。
```
@@ -148,27 +154,34 @@ events.loop();
### obverseNotification()
开启通知(包括Toast)监听。
```
events.obverseNotification();
events.onNotification(function(notification){
log(notification.getText());
});
events.onToast(function(toast){
log(toast.getText());
});
```
### toast事件
### 事件: 'toast'
* toast \<Object\>
* getText() 获取Toast的文本内容
* getPackageName() 获取发出Toast的应用包名
### 事件: 'notification'
* notification \<Notification\> 通知
* notification \<Object\> 通知
```
events.observeNotification();
events.on("notification", function(notification){
log(notification.
log(notification);
});
```
# EventEmitter
### EventEmitter.defaultMaxListeners

View File

@@ -244,6 +244,7 @@
"emitter",
"observeKey",
"observeTouch",
"observeNotification",
"onKeyDown",
"onKeyUp",
"onceKeyDown",

View File

@@ -0,0 +1,9 @@
auto();
events.observeNotification();
events.onToast(function(toast){
var pkg = toast.getPackageName();
log("Toast内容: " + toast.getText() +
" 来自: " + getAppName(pkg) +
" 包名: " + pkg);
});
toast("监听中请在日志中查看记录的Toast及其内容");

View File

@@ -0,0 +1,21 @@
auto();
events.observeNotification();
events.onNotification(function(info, notification){
printNotification(info, notification);
});
toast("监听中,请在日志中查看记录的通知及其内容");
function printNotification(info, notification){
log("应用包名: " + info.getPackageName());
log("通知文本: " + info.getTexts());
log("通知优先级: " + notification.priority);
log("通知目录: " + notification.category);
log("通知创建时间: " + new Date(notification.creationTime));
log("通知时间: " + new Date(notification.when));
log("通知数: " + notification.number);
log("通知摘要: " + notification.tickerText);
for(var i = 0; i < notification.actions.length; i++){
var action = notification.actions[i];
log("通知" + (i + 1) + ": " + action.title);
}
}

View File

@@ -0,0 +1 @@
engines.stopAllAndToast();

View File

@@ -0,0 +1,14 @@
var scriptsPath = "/sdcard/脚本/";
if(!files.exists(scriptsPath)){
scriptsPath = "/sdcard/Scripts/";
}
var scriptFiles = files.listDir(scriptsPath, function(name){
return name.endsWith(".auto");
});
var i = dialogs.singleChoice("请选择要运行的脚本", scriptFiles);
if(i < 0){
exit();
}
var path = files.join(scriptsPath, scriptFiles[i]);
engines.execAutoFile(path);

View File

@@ -0,0 +1,6 @@
var script = "toast('Hello, Auto.js');" +
"sleep(3000);" +
"toast('略略略');";
var execution = engines.execScript(script);
sleep(1000);
execution.getEngine().forceStop();

View File

@@ -0,0 +1,14 @@
var scriptsPath = "/sdcard/脚本/";
if(!files.exists(scriptsPath)){
scriptsPath = "/sdcard/Scripts/";
}
var scriptFiles = files.listDir(scriptsPath, function(name){
return name.endsWith(".js");
});
var i = dialogs.singleChoice("请选择要运行的脚本", scriptFiles);
if(i < 0){
exit();
}
var path = files.join(scriptsPath, scriptFiles[i]);
engines.execScriptFile(path);