# Robotmon JavaScript APIs
Only support ES5
## Contents
* [JavaScript Events](#javascrip-svents)
* [JavaScript Interface](#javascrip-interface)
* [JavaScript Raw APIs](#javascrip-apis)
* [RBM library APIs](#rbm-library-apis)
* [gRPC APIs](#grpc-apis)
* [Debug](#debug)
## JavaScript Events
Add the following `<script>` in the `<head>` section of `index.html`
`start()` and `stop()` should defined in `index.js`
```html
<script>
function onEvent(eventType) {
if (eventType == 'OnPlayClick') {
JavaScriptInterface.runScript(`start();`);
} else if (eventType == 'OnPauseClick') {
JavaScriptInterface.runScript('stop();');
}
}
function onLog(message) {
console.log(message);
}
</script>
```
|event name|
|---|
|OnMenuClick|
|OnPlayClick|
|OnPauseClick|
|OnLogClick|
|OnSettingClick|
|OnCloseClick|
## JavaScript Interface
```javascript
runScript(script)
```
* `script` String
```javascript
runScriptCallback(script, callback)
```
* `script` String
* `callback` String
```javascript
clickIconButton()
```
Click the `app icon button` on floating widget.
```javascript
clickPlayButton()
```
Click the `play button` on floating widget.
```javascript
clickPauseButton()
```
Click the `pause button` on floating widget.
```javascript
clickLogButton()
```
Click the `log button` on floating widget.
```javascript
clickSettingButton()
```
Click the `setting button` on floating widget.
```javascript
clickCloseButton()
```
Click the `close button` on floating widget.
```javascript
setXY(x, y)
```
* `x` Integer
* `y` Integer
Set the position of the floating widget.
```javascript
getX()
```
Returns `Integer` - The x position of the floating widget.
```javascript
getY()
```
Returns `Integer` - The y position of the floating widget.
```javascript
showMenu()
```
Show the menu on floating widget.
```javascript
hideMenu()
```
Hide the menu on floating widget.
```javascript
showPlayButton()
```
Show the `play button` on floating widget.
```javascript
showPauseButton()
```
Show the `pause button` on floating widget.
## JavaScript Raw APIs
#### `getScreenSize()`
Returns `Object` - `{width: Integer, height: Integer}`
```javascript
var sizeObj = getScreenSize();
console.log(sizeObj.width, sizeObj.height);
// 1080 1920
```
#### `getScreenshot()`
Returns `Integer` - The image pointer
```javascript
var img = getScreenshot();
console.log(img);
// 122344533 <- image pointer
releaseImage(img); // Don't forgot release a pointer
```
#### `getScreenshotModify(cropX, cropY, cropWidth, cropHeight, resizeWidth, resizeHeight, qualitys)`
Get screenshot, crop and resize. For speeding up screenshot.
* `cropX` Integer
* `cropY` Integer
* `cropWidth` Integer
* `cropHeight` Integer
* `resizeWidth` Integer
* `resizeHeight` Integer
* `quality` Integer
Returns `Integer` - The image pointer
```javascript
var image = getScreenshotModify(200, 200, 100, 100, 50, 50, 80);
console.log(image); // image width = 50, height = 50
// 12333122
releaseImage(image);
```
#### `execute(command)`
Call exec command in android system. It's permission is same as `adb shell`
* `command` String
Returns `String` - The result of the execution
```javascript
var result = execute("ls -al /sdcard");
console.log(result);
// drwxr-xr-x 2 root root 64B 12 14 23:44 Robotmon
```
#### `tap(x, y, during)`
Simulate a tap event
* `x` Integer
* `y` Integer
* `during` Integer
```javascript
tap(200, 200, 10);
// Will inject a tap down and a tap up event to system
```
#### `tapDown(x, y, during)`
* `x` Integer
* `y` Integer
* `during` Integer
```javascript
tapDown(200, 200, 40);
// Will inject a tapDown event to system
```
#### `tapUp(x, y, during)`
* `x` Integer
* `y` Integer
* `during` Integer
```javascript
tapUp(200, 200, 40);
// Will inject a tapUo event to system
```
#### `moveTo(x, y, during)`
moveTo should be betewwn `tapDown` and `tapUp`
* `x` Integer
* `y` Integer
* `during` Integer
```javascript
tapDown(500, 300, 40);
moveTo(500, 600, 40);
tapUp(500, 600, 40);
// Will inject a swipe down event
```
#### `swipe(x1, y1, x2, y2, during)`
Simulate a swipe event, using `tapDown`, `moveTo` and `tapUp` event. This function may not work in some game, you should implement yourself.
* `x1` Integer
* `y1` Integer
* `x2` Integer
* `y2` Integer
* `during` Integer
```javascript
swipe(500, 300, 40); // same as above example
// Will inject a swipe down event
```
#### `keycode(label, during)`
Send a key code event to system
Like adb shell input keyevent command
[Android Keycode List](https://developer.android.com/reference/android/view/KeyEvent.html)
* `label` String
* `during` Integer
```javascript
keycode('HOME', 40); // same as keycode('KEYCODE_HOME', 40);
// Will send a HOME event to system
```
#### `typing(words, during)`
Only allow English words
* `words` String
* `during` Integer
```javascript
typing('Hello!', 100);
// Will type 'H' 'e' 'l' 'l' 'o' '!' 6 words
```
### OpenCV
#### `clone(sourceImg)`
Duplicate an image to another.
* `sourceImg` Integer
Returns `Integer` - The image pointer
```javascript
var oriImage = getScreenshot();
for (var i = 0; i < 10; i++) {
var cloneImage = clone(oriImage);
// modify clone Image here
smooth(cloneImage, 1, 5); // blur
release(cloneImage);
}
release(oriImage);
```
#### `smooth(sourceImg, smoothType, size)`
Same as OpenCV `smooth()` function.
* `sourceImg` Integer
* `smoothType` Integer
* `size` Integer
|smoothType|description|
|---|---|
|0|CV_BLUR_NO_SCALE|
|1|CV_BLUR|
|2|CV_GAUSSIAN|
|3|CV_MEDIAN|
|4|CV_BILATERAL|
```javascript
var img = getScreenshot();
smooth(img, 2, 5); // Gaussian blur
saveImage(img, getStoragePath + '/smooth.png');
releaseImage(img);
```
#### `convertColor(sourceImg, code)`
Same as OpenCV `cvtColor()`. Not support different channels. If you want to convert to gray, please use bgrToGray.
Note that `getScreenshot` and `getScreenshotModify` is BGR order;
* `sourceImg` Integer
* `code` Integer
|code|description|
|---|---|
|40|CV_BGR2HSV|
|52|CV_BGR2HLS|
See more: [OpenCV Types](https://github.com/opencv/opencv/blob/2.4/modules/imgproc/include/opencv2/imgproc/types_c.h)
```javascript
var img = getScreenshot();
// Convert BGR to HSV color
convertColor(img, 40);
releaseImage(img);
```
#### `bgrToGray(sourceImg)`
Convert form bgr (3 channels) to gray (1 channel).
* `sourceImg` Integer
Returns `Integer` - The gray image pointer
```javascript
var img = getScreenshot();
var gray = bgrToGray(img); // gray image
releaseImage(img);
releaseImage(gray);
```
#### `absDiff(sourceImg, targetImg)`
Same as OpenCV `adbdiff()`.
* `sourceImg` Integer
* `targetImg` Integer
Returns `Integer` - The image pointer of the difference
```javascript
var img1 = getScreenshot();
sleep(100);
var img2 = getScreenshot();
var diff = absDiff(img1, img2); // in gray order
releaseImage(img1);
releaseImage(img2);
releaseImage(diff);
```
#### `threshold(sourceImg, thr, maxThr, code)`
Same as OpenCV `threshold()`.
* `sourceImg` Integer
* `thr` Float
* `maxThr` Float
* `code` Integer
|code|description|
|---|---|
|0|CV_THRES_BINARY|
See more: [OpenCV Types](https://github.com/opencv/opencv/blob/2.4/modules/imgproc/include/opencv2/imgproc/types_c.h)
```javascript
keycode('MENU');
sleep(1000);
var img1 = getScreenshot();
keycode('HOME');
sleep(1000);
var img2 = getScreenshot();
var diff = absDiff(img1, img2); // in gray order
threshold(diff, 100, 255); // set to 0 if <= 100, set to 255 if > 100
var value = getImageColor(diff, 500, 200); // value => {r":255,"g":0,"b":0","a":0}
console.log(value['r']); // current diff value is show on 'r'
// 255
releaseImage(img1);
releaseImage(img2);
releaseImage(diff);
```
#### `eroid(sourceImg, width, height, x, y)`
Same as OpenCV `eroid`.
`width`, `height`, `x`, `y` is `getStructuringElement()` parameters.
* `sourceImg` Integer
* `width` Integer
* `height` Integer
* `x` Integer
* `y` Integer
```javascript
var img = getScreenshot();
threshol
没有合适的资源?快使用搜索试试~ 我知道了~
在Android上运行Javascript。截图,触摸,..._JavaScript_HTML_下载.zip
共4593个文件
png:4326个
js:105个
sh:29个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 89 浏览量
2023-04-25
11:26:58
上传
评论
收藏 25.75MB ZIP 举报
温馨提示
在Android上运行Javascript。截图,触摸,..._JavaScript_HTML_下载.zip
资源推荐
资源详情
资源评论
收起资源包目录
在Android上运行Javascript。截图,触摸,..._JavaScript_HTML_下载.zip (4593个子文件)
.babelrc 41B
.browserslistrc 30B
find_diff.cpp 2KB
make_images.cpp 1KB
rsettingsui.css 517KB
simplesettings.css 384KB
bootstrap.min.css 118KB
bootstrap.min.css 118KB
bootstrap.min.css 118KB
select2.min.css 15KB
select2.min.css 15KB
select2.min.css 15KB
index.css 3KB
index.css 3KB
index.css 2KB
.gitignore 231B
.gitignore 76B
.gitignore 47B
.gitignore 21B
.gitignore 21B
.gitignore 21B
index.html 42KB
index.html 32KB
index.html 28KB
index.html 28KB
index.html 27KB
index.html 26KB
index.html 21KB
index.html 21KB
index.html 20KB
index.html 18KB
index.html 17KB
index.html 16KB
index.html 14KB
index.html 12KB
index.html 12KB
index.html 11KB
index.html 10KB
index.html 6KB
index.html 6KB
index.html 5KB
index.html 4KB
index.html 4KB
index.html 3KB
index.html 3KB
example.html 3KB
index.html 908B
index.html 832B
index.html 514B
favicon.ico 4KB
rsettingsui.umd.js 1.17MB
index.js 694KB
index.js 680KB
rsettingsui.umd.min.js 535KB
simplesettings.umd.min.js 261KB
index.js 115KB
index.js 115KB
index.js 88KB
index.js 87KB
jquery.min.js 85KB
jquery.min.js 85KB
jquery.min.js 85KB
index.js 70KB
select2.min.js 65KB
select2.min.js 65KB
select2.min.js 65KB
index.js 60KB
index.js 60KB
index.js 51KB
index.js 46KB
main.js 43KB
index.js 38KB
bootstrap.min.js 36KB
bootstrap.min.js 36KB
bootstrap.min.js 36KB
setting.js 33KB
setting.js 33KB
index.js 32KB
index.js 27KB
index.js 23KB
index.js 22KB
index.js 22KB
command.js 21KB
command.js 21KB
command_html.js 20KB
command_html.js 20KB
index.js 19KB
framework.js 18KB
RBM-0.0.3.js 16KB
index.js 14KB
auto_attack_ai.js 13KB
auto_attack_ai.js 13KB
friend.js 13KB
friend.js 13KB
in_stage.js 12KB
in_stage.js 12KB
check_stage.js 11KB
check_stage.js 11KB
bootbox.min.js 10KB
bootbox.min.js 10KB
共 4593 条
- 1
- 2
- 3
- 4
- 5
- 6
- 46
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功