The Custom Function

For more flexibility, you can create custom functions to manipulate data and functions, through the basic introduction in this chapter, you will quickly get started to using Blackey Scripts.

Our functions

Functions

Do this

find(path)

Given the path of a selected image, search whether the image exists on the current screen.

click(position,interval)

Given the path of a selected image, click/double-click the coordinates of the image with interval the timer setting.

dclick(path)

If there is no specific image on the screen, the click action is still performed at the coordinates.

press(position)

Press at a specificed coordinates.

move(position)

Move to a specific coordinates.

release(position)

release the mouse button

wheel(direction, position)

Occurs when the mouse wheel moves while the control has focus. The value 0 means mouse wheel moved UP, and 1 means mouse wheel moved DOWN.

keycode(value)

Transmitting the KeyEvent code to the device.

input(string)

Sending string to the device.

print(expression1, …)

printing the specified message to the screen, or other standard output device.

random(value)

Returns a random integer from 0 to -1

msleep(value)

The time interval for which execution is to be suspended, in milliseconds

find(path)

The relative path of the captured image can be recorded via Image recognition or Recording . And you also can add statements such as if-else syntax to perform more advanced scripts.

if (find(“res/20190809-131033.png”)) {

    print(“Yes, we find it!”);

} else {

    print(“No, we could not find it!”);

}

click(position,interval)

To get the position of the captured image via Image recognition or Recording , if there is no specific image on the screen, the click action is still performed at the coordinates of 100(ms) by default.

Tip

By default, the click operation will be performed at the coordinate of 100 (ms), you also can set the interval less than 100 ms. Kindly note that the function does not need to fill in the unit.

if (find(“res/20190809-131033.png”)) {

    click(“res/20190809-131033.png”);

} else {

    print(“No, we could not find it!”);

}

dclick(path)

The function is similar to click, use this API to trigger a double click.

press(position)

Android key events(similar to ACTION_SCROLL) are generally accompanied by three actions, ACTION_DOWN->ACTION_MOVE->ACTION_UP, If we calculate the distance between two points, the scroll action is longer than the long press action.

move(position)

This action has a considerable correlation with press action and release action, mainly recording the moving coordinates.

release(position)

This action has a considerable correlation with the press action and the release action, mainly recording the moving coordinates when the key is released.

wheel(position)

The wheel events can also be recorded. The advantage of using recording function is that you can accurately locate the coordinates you want to scroll. The value 0 means mouse wheel moved UP, and 1 means mouse wheel moved DOWN. Let us scroll the mouse action, as illustrated below.

click("res/20211105-150410.png");
msleep(80);
msleep(1418);
wheel(1, pos(0.454268, 0.404372));
msleep(28);
wheel(1, pos(0.454268, 0.404372));
msleep(7);
wheel(1, pos(0.454268, 0.404372));
wheel(1, pos(0.454268, 0.404372));
wheel(1, pos(0.454268, 0.404372));
...
mouse wheel

Fig. 72 The script will automatically detect the mouse scrolling coordinates and record them in the editor area.

keycode(value)

The KeyEvent code transmitted to the device is similar to the key code action, which is generally handled by one ACTION_UP action and one or more ACTION_DOWN actions.

We simplified this press method in Blackey Script. When the script runs to keycode(value), it will automatically send ACTION_DOWN and ACTION_UP events, and it is the reason that the script does not support the function of long-pressing.

The keycode can be automatically filled in by the blackey script during recording, or you can edit and call keycode to fill in the key value.

Keycode

Action

102

Power

172

Home

5000

Rotate

key code(102)

Fig. 73 腳本自動偵測操作並填入相對應之keycode

input(string)

The input function is used for sending a string to the device. The device needs to access the input area before executing the input function. The illustration below shows the input function in the script.

// Input the string directly
    input(“Hello World!”);

// Input string according to the variable
    myString = “Hello Blackey”;
    input(myString);

Hint

When using input function, it needs to enable BlacKeyBoard

random (value)

The random function is for calling function randomly, we only need to fill in the expected range, the script will return a value between 0 and -1. For example, we can edit our script as shown below to get random numbers from 1 to 10.

randomValue = 1 + random(10);

x = 0;
while (x < 10) {

    print(x, random(10));
    x = x+1;

}

msleep (value)

The timing of use is when you need to delay the execution of the next expression. In the script recording mode, it will automatically determine the interval time between your actions and fill in the msleep() function. Visit our recording and image recognition examples, the script automatically detect the interval we mentioned.

Tip

The unit of msleep is milliseconds (1/1000 sec).

Check script editor or Back to the top