JavaScript Raw APIs

Low level APIs for controlling your android phone

getScreenSize()

Returns Object - {width: Integer, height: Integer}

var sizeObj = getScreenSize();
console.log(sizeObj.width, sizeObj.height);
// 1080 1920

getScreenshot()

Returns Integer - The image pointer

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

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

tap(x, y, during)

Simulate a tap event

  • x Integer

  • y Integer

  • during Integer

tapDown(x, y, during)

  • x Integer

  • y Integer

  • during Integer

tapUp(x, y, during)

  • x Integer

  • y Integer

  • during Integer

moveTo(x, y, during)

moveTo should be betewwn tapDown and tapUp

  • x Integer

  • y Integer

  • during Integer

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

keycode(label, during)

Send a key code event to system Like adb shell input keyevent command Android Keycode Listarrow-up-right

  • label String

  • during Integer

typing(words, during)

Only allow English words

  • words String

  • during Integer

OpenCV

clone(sourceImg)

Duplicate an image to another.

  • sourceImg Integer

Returns Integer - The image pointer

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

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 Typesarrow-up-right

bgrToGray(sourceImg)

Convert form bgr (3 channels) to gray (1 channel).

  • sourceImg Integer

Returns Integer - The gray image pointer

absDiff(sourceImg, targetImg)

Same as OpenCV adbdiff().

  • sourceImg Integer

  • targetImg Integer

Returns Integer - The image pointer of the difference

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 Typesarrow-up-right

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

dilate(sourceImg, width, height, x, y)

Same as OpenCV dilate.

width, height, x, y is getStructuringElement() parameters.

  • sourceImg Integer

  • width Integer

  • height Integer

  • x Integer

  • y Integer

inRange(sourceImg, minB, minG, minR, minA, maxB, maxG, maxR, maxA)

Same as OpenCV inRange + clone + mask. Filter with range color and clone to new image.

  • sourceImg Integer

  • minB Integer

  • minG Integer

  • minR Integer

  • minA Integer

  • maxB Integer

  • maxG Integer

  • maxR Integer

  • maxA Integer

Returns Integer - The filtered image pointer

outRange(sourceImg, minB, minG, minR, minA, maxB, maxG, maxR, maxA)

Same as OpenCV inRange + clone + not + mask. Filter without range color and clone to new image.

  • sourceImg Integer

  • minB Integer

  • minG Integer

  • minR Integer

  • minA Integer

  • maxB Integer

  • maxG Integer

  • maxR Integer

  • maxA Integer

Returns Integer - The filtered image pointer

cloneWithMask(sourceImg, mask)

Same as OpenCV copyTo. Clone image with mask (only support 1 channel)

  • sourceImg Integer

  • mask Integer

Returns Integer - new image pointer with mask

houghCircles(sourceImg, method, dp, minDist, p1, p2, minR, maxR)

Same as OpenCV houghCircles. For finding circles.

  • sourceImg Integer

  • method Integer (3 = CV_HOUGH_GRADIENT)

  • dp Float (1) (ratio between input image and input params.)

  • minDist Float (min distance between circles)

  • p1 Float (canny parameter)

  • p2 Float (canny parameter)

  • minR Integer (min radius)

  • maxR Integer (max radius)

Returns Object - Array of circles

canny(sourceImg, t1, t2, apertureSize)

Same as OpenCV canny

  • sourceImg Integer

  • t1 Float

  • t2 Float

  • apertureSize Integer

Returns Integer - The canny image pointer

findContours(cannyImgPtr, minArea, maxArea)

Same as OpenCV findContours.

  • cannyImgPtr Integer (Canny image as input)

  • minArea Float

  • maxArea Float

Returns Object - {"0": {x: Integer, y: Integer}

drawCircle(sourceImg, x, y, radius, r, g, b, a)

Draw circle in an image.

  • sourceImg Integer

  • x Integer

  • y Integer

  • radius Integer

  • r Integer

  • g Integer

  • b Integer

  • a Integer

getIdentityScore(sourceImg, targetImg)

  • sourceImg Integer

  • targetImg Integer

Returns Float - The identity score

cropImage(sourceImg, x, y, width, height)

Crop image.

  • x Integer

  • y Integer

  • width Integer

  • height Integer

Returns Integer - The image pointer

findImage(sourceImg, targetImg)

Using OpenCV Template Match to fing image.

  • sourceImg Integer

  • targetImg Integer

Returns Object - {x: Integer, y: Integer, score: Float}

findImages(sourceImg, targetImg, scoreLimit, resultCountLimit, withoutOverlap)

Same as findImage(), but find mulitple times.

  • sourceImg Integer

  • targetImg Integer

  • scoreLimit Integer

  • resultCountLimit Integer

  • withoutOverlap Boolean

Returns String - {"0": {"x": Integer, "y": Integer, "score": Float}, "1": {"x": Integer, "y": Integer, "score": Float}}, Key is String!

resizeImage(sourceImg, width, height)

Resize image.

  • width Integer

  • height Integer

Returns Integer - The image pointer

releaseImage(imgPtr)

Very Important! You should call this function with all imgPtrs.

  • imgPtr Integer

getImageColor(sourceImg, x, y)

Get color of point from an image.

  • sourceImg Integer

  • x Integer

  • y Integer

Returns Object - {r: Integer, g: Integer, b: Integer, a: Integer}

getImageSize(imgPtr)

  • imgPtr Integer

Returns Object - {width: Integer, height: Integer}

saveImage(imgPtr, path)

Save image to disk.

  • imgPtr Integer

  • path String

openImage(path)

Open image from disk.

  • path String

Returns Integer - The image pointer

sleep(milliseconds)

Like sleep function in C language, pause current process.

  • milliseconds Integer

getStoragePath()

Get Robotmon folder. Like /sdcard/Robotmon.

Returns String - The storage path

getImageFromURL(url)

Get image from an url.

  • url String

Returns Integer - The image pointer

getImageFromBase64(base64)

Get image from a base64 string.

  • base64 String

Returns Integer - The image pointer

getBase64FromImage(imgPtr)

Get base64 string from an image.

  • imgPtr Integer

Returns String - base64

readFile(path)

Read a file as string.

  • path String

Returns String - The text of the file

writeFile(path, text)

Write a string to a file.

  • path String

  • text String

encrypt(script)

Encrypted a string

  • script String

Returns String - The encrypted script

runEncryptedScript(script)

Run a encrypted javascript string.

  • script String - The script is encrypted by encrypt

runScript(script)

Run a javascript string.

  • script String

httpClient(method, url, body, headers)

Do a http request.

  • method String

  • url String

  • body String

  • headers Object

Returns String - The result

importJS(library)

Import an JS library.

  • library String

getVirtualButtonHeight()

Returns Integer - The height of the virtual button

Last updated