AutoTouchDocuments

AutoTouch Document

Applicable to version 5.1.0 or higher

Table of Contents

Usage

How to install?

How to use Activator?

How to record?

How to play script?

How to set play settings for script?

How to take screenshot?

How to write a script?

How to use the “Function Helper” while script coding?

How to write and manage scripts on the computer?

How to use Package to orgainize the script project?

How to encrypt the scripts?

How to sell your script in Script Store?

How to download and buy scripts from Script Store?

How to buy AutoTouch license?

Script

Basis

You can learn how to use Lua language from here:《Lua Official Reference Manual

Develop Tool

LuaStudio is aprofessional development environment for debugging Lua script in your applications. It’s familiar and fast and you’ll wonder how you ever worked without it.

Coordinate, Size and Orientation System

AutoTouch uses pixel based Native Resolution as the coordinate and size system. Resolutions of different iOS devices are here, for example, screen size of iPhone X is 1125 x 2436.

Origin point (0, 0) is alwasy at left-top of the Application Interface, regardless of the device orientation. Consider only the App interface while using these functions: touchDown,touchMove,touchUp,getColors,findColors,findImage.

For example

Extension Libraries

AutoTouch has some extension libraries built in, while you can also add extension libraries by yourself, just put .so files at /usr/local/lib/lua/5.3 and .lua files at /var/mobile/Library/AutoTouch/Library/LuaLibraries.

ATTENSION: DO NOT use script filename same as the libraries’ name, such as lcurl, lfs, lsqlite3.

LuaCURL

curl is used in command lines or scripts to transfer data. It is also used in cars, television sets, routers, printers, audio equipment, mobile phones, tablets, settop boxes, media players and is the internet transfer backbone for thousands of software applications affecting billions of humans daily.

It supports DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, Telnet and TFTP. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, HTTP/2, cookies, user+password authentication (Basic, Plain, Digest, CRAM-MD5, NTLM, Negotiate and Kerberos), file transfer resume, proxy tunneling and more.

Learn More

Examples:

-- HTTP Get
local curl = require('lcurl')
curl.easy{
    url = 'http://httpbin.org/get',
    httpheader = {
      "X-Test-Header1: Header-Data1",
      "X-Test-Header2: Header-Data2",
    },
    writefunction = alert -- use io.stderr:write()
  }
  :perform()
:close()

-- HTTP Post
curl.easy()
  :setopt_url('http://posttestserver.com/post.php')
  :setopt_writefunction(io.write)
  :setopt_httppost(curl.form() -- Lua-cURL guarantee that form will be alive
    :add_content("test_content", "some data", {
      "MyHeader: SomeValue"
    })
    :add_buffer("test_file", "filename", "text data", "text/plain", {
      "Description: my file description"
    })
    :add_file("test_file2", "BuildLog.htm", "application/octet-stream", {
      "Description: my file description"
    })
  )
  :perform()
:close()

LuaSocket

LuaSocket is a Lua extension library which supported TCP, UDP, SMTP, HTTP, FTP protocols. Learn how to use it from the Learn More.

LuaSec

LuaSec is a binding for OpenSSL library to provide TLS/SSL communication. It takes an already established TCP connection and creates a secure session between the peers.Learn More

LuaSqlite3

LuaSQLite 3 is a thin wrapper around the public domain SQLite3 database engine. Learn More

json.lua

json.lua provides operation methods on json. GitHub LICENSE

Usage

local json = require "json"
local jsonString =json.encode({ 1, 2, 3, { x = 10 } }) -- Returns '[1,2,3,{"x":10}]'
local luaTable = json.decode('[1,2,3,{"x":10}]') -- Returns { 1, 2, 3, { x = 10 } }

Plist

Plist library provides a batch of methods to operate on plist files.

Usage

local plist = require("plist")

-- Read a plist file, return it as a lua table, return nil if failed.
local luaTable = plist.read(plistFilePath);

-- Write a lua table as a plist into a file, the foramt parameter specifis "xml", "binary" you want to write with.
local done = plist.write(luaTable, plistFilePath, format);

-- Load a plist string to lua table.
local luaTable = plist.load(plistString);

-- Dump a lua table to plist data with format "xml" or "binary"
local plistData = plist.dump(luaTable, format);

Penlight

A set of pure Lua libraries focusing on input data handling (such as reading configuration files), functional programming (such as map, reduce, placeholder expressions,etc), and OS path management. GitHub Document LICENSE

It has plenty of modules:

Paths, Files and Directories

Application Support

Extra String Operations

Extra Table Operations

Iterators, OOP and Functional

LuaFileSystem

LuaFileSystem is a Lua library developed to complement the set of functions related to file systems offered by the standard Lua distribution.

LuaFileSystem offers a portable way to access the underlying directory structure and file attributes.Learn More

WebSocket

This module provides Lua modules for Websocket Version 13 conformant clients and servers.

GitHub LICENSE Examples

Usage

-- Client
-- connects to a echo websocket server running a localhost:8080
-- sends a strong every second and prints the echoed messages
-- to stdout

local ev = require'ev'
local ws_client = require('websocket.client').ev()

ws_client:on_open(function()
    print('connected')
  end)

ws_client:connect('ws://echo.websocket.org','echo')

ws_client:on_message(function(ws, msg)
    print('received',msg)
  end)

local i = 0

ev.Timer.new(function()
    i = i + 1
    ws_client:send('hello '..i)
end,1,1):start(ev.Loop.default)

ev.Loop.default:loop()

Extension Functions

Extension functions are used to extend Lua language. Thus, the device can simulate some human abilities of operating the mobile phone. Moreover, extension functions also support functions including: screenshot, color searching, color matching, and picture matching.

touchDown(id, x, y)

Press the coordinate (x,y) on the screen.

Parameters

Parameter Type Specification
id Integer Finger ID. is used to mark a finger in single-touch or multi-touch.
x Float x-coordinate on the screen
y Float y-coordinate on the screen

Return

None

Examples

-- Press by one finger at coordinate (100,200).
touchDown(0, 100, 200); 

-- Press by three fingers at three locations on the screen.
touchDown(0, 100, 200);
touchDown(1, 200, 300);
touchDown(2, 300, 400);

-- Implement a tap function
function tap(x, y)
    touchDown(0, x, y);
    usleep(16000);
    touchUp(0, x, y);
end

-- Tap at (100, 200)
tap(100, 200);

touchMove(id, x, y)

Move the finger to coordinate (x,y).

Parameters

Parameter Type Specification
id Integer Finger ID. is used to mark a finger in single-touch or multi-touch.
x Float x-coordinate on the screen
y Float y-coordinate on the screen

Return

None

Examples

-- Press by one finger at coordinate (100,200) and move the finger to coordinate (200,200).
touchDown(0, 100, 200);
usleep(16000);
touchMove(0, 200, 200);

-- Press by three fingers at three locations on the screen and move to new location.
touchDown(0, 100, 200);
touchDown(1, 200, 300);
touchDown(2, 300, 400);
usleep(16000);
touchMove(0, 150, 250);
touchMove(1, 250, 350);
touchMove(2, 350, 450);

touchUp(id, x, y)

Lift the finger from coordinate (x,y)

Parameters

Parameter Type Specification
id Integer Finger ID. is used to mark a finger in single-touch or multi-touch.
x Float x-coordinate on the screen
y Float y-coordinate on the screen

Return

None

Examples

-- Click the screen once by one finger at coordinate (100,200).
touchDown(0, 100, 200);
usleep(16000);
touchUp(0, 100, 200);

-- Press by three fingers at three locations on the screen, move to new location, and then lift the finger.
touchDown(0, 100, 200);
touchDown(1, 200, 300);
touchDown(2, 300, 400);
usleep(16000);
touchMove(0, 150, 250);
touchMove(1, 250, 350);
touchMove(2, 350, 450);
usleep(16000);
touchUp(0, 150, 250);
touchUp(1, 250, 350);
touchUp(2, 350, 450);

keyDown(keyType)

Simulate the pressing of physical key.

Parameters

Parameter Type Specification
keyType Integer Physical key identification. Now you can use these physical keys.

Return

None

Examples

-- Simulate the pressing of Home Key.
keyDown(KEY_TYPE.HOME_BUTTON);

-- How to simulate a key pressing?
function keyPress(keyType)
    keyDown(keyType);
    usleep(10000);
    keyUp(keyType);
end
keyPress(KEY_TYPE.HOME_BUTTON);

-- How to simulate a screen lock function?
function lockScreen()
    keyDown(KEY_TYPE.POWER_BUTTON);
    keyUp(KEY_TYPE.POWER_BUTTON);
end

-- How to simulate a screen unlock function?
function unlockScreen()
    keyDown(KEY_TYPE.POWER_BUTTON);
    keyUp(KEY_TYPE.POWER_BUTTON);

    usleep(1000000);

    local w, h = getScreenResolution();

    local x = 10;
    local gap = 120;
    touchDown(0, x, 200);
    while x < w do
        x = x + gap;
        usleep(16000);
        touchMove(0, x, 200);
    end
    touchUp(0, x, 200);
end

keyUp(keyType)

Simulate the lifting of physical key.

Parameters

Parameter Type Specification
keyType Integer Physical key identification. Now you can use these physical keys.

Return

None

Examples

-- Simulate the action of pressing and lifting Home Key.
keyDown(KEY_TYPE.HOME_BUTTON);
usleep(10000);
keyUp(KEY_TYPE.HOME_BUTTON);

getColor(x, y)

Get the color value of the pixel point of the specified coordinate on current screen.

Parameters

Parameter Type Specification
x Float x-coordinate on the screen
y Float y-coordinate on the screen

Return

Return Type Specification
color Integer Integer color value of the pixel point

Examples

local color = getColor(100, 200)
alert(string.format("Pixel color is :%d", color))
-- Pop up color: 16777215

-- Keep gettting color of a location until it matches a specify color
local color
repeat
   color = getColor(100, 200)
   usleep(50000) -- Wait a while
until( color == 123456 )
-- Continue to do what's next

getColors(locations)

Get the color values of the pixel points of the specified coordinates on current screen.

Parameters

Parameter Type Specification
locations table A grouo of coordinates, just as { {x1,y1}, {x2,y2}, {x3,y4} }

Return

Return Type Specification
colors table Colors gotten with corresponding order.

Examples

local result = getColors({ {100, 200}, {200, 300}, {300, 400} });
for i, v in pairs(result) do
    log(string.format("Gotten color:%d", v));
end

findColor(color, count, region, debug)

Search the coordinates of the pixel points matching the specified color on current screen.

Parameters

Parameter Type Specification Optional Default
color Integer Matched color value. NO  
count Integer The number refers to how many matched pixel points is found at most. 0 is default setting, which shows all matching points are found. 1 refers to only the first matching pixel point is found. 2 refers to only the first two pixel points are found. The less the number is, the faster the speed is. NO 0
region table You only search the result in the specified area. This area is the table type including four values {x, y, width, height}. The four values respectively represent the coordinate x, coordinate y, width, and height of the rectangular area. {100,100,200,200} is an example. If you do not want to specify the area, just input nil. NO nil
debug boolean If pass debug=true, it will produce a image ends with “-Debug.PNG” marked the matching areas. YES false

Return

Return Type Specification
locations table Coordinates of matched pixel points. For example: { {x1, y1}, {x2, y2}, … }

Example

-- Example 1:
local result = findColor(0x0000ff, 2, nil);
for i, v in pairs(result) do
    log(string.format("Found pixel: x:%f, y:%f", v[1], v[2]));
end

-- Example 2:
local result = findColor(0x00ddff, 0, {100, 50, 200, 200});
for i, v in pairs(result) do
    log(string.format("Found pixel: x:%f, y:%f", v[1], v[2]));
end

-- Example 3:
local region = {100, 50, 200, 200};
local result = findColor(0x00ddff, 0, region);
for i, v in pairs(result) do
    log(string.format("Found pixel: x:%f, y:%f", v[1], v[2]));
end

-- Example 4:
-- Keep finding a speficied color until it's found.
local locations
repeat
   local locations = findColor(0x0000ff, 2, nil);
   usleep(50000) -- Wait a while
until(#locations > 0)
-- Log the locations if found
for i, v in pairs(locations) do
    log(string.format("Found pixel: x:%f, y:%f", v[1], v[2]));
end

Internal Implementation

function findColor(color, count, region)
    return findColors({ {color,0,0} }, count, region);
end

findColors(colors, count, region, debug)

Search all rectangular areas matching “specified color and their corresponding location and return the coordinate of the pixel point matching the first color in the rectangular area. This function has the search efficiency and availability far beyond findImage. For example, you need not match the whole key picture, but only match the anchors’ color and their corresponding location on the key. You can specify the number of the results by count parameter. 0 refers to all, 1 refers to the first one, and 2 refers to the first tow. region parameter can specify the search area, which is the table type {x,y,width, height}. You only input nil if no data is specified.

This function can use the “auxiliary” tool in the “Extension Function” of the script-editing interface to select the anchors’ colors from the screenshot and get their corresponding location to the function’s parameter automatically.

The coordinate of the pixel point pointed by the arrow is the coordinate of the return value.

IMG_0361.PNG-101.9kB

Parameters

Parameter Type Specification Optional Default
colors table Include some color and their corresponding location, such as:{ {0x00ddff,0,0}, {0x00eeff,10,10}, {0x0000ff,0,20} }. The small table in the big table includes 3 values: the first is the color value. The second and the third are the corresponding locations of the colors to the first color. The corresponding location of the first color’s table is always (0,0). {0x00ddff,0,0} is an example. The location values of the successive colors are their locations corresponding to the first color. The matched rectangular area can be found on the screen upon these colors and corresponding location relation. NO  
count Integer The number refers to how many matched pixel points is found at most. 0 is default setting, which shows all matching points are found. 1 refers to only the first matching pixel point is found. 2 refers to only the first two pixel points are found. The less the number is, the faster the speed is. NO 0
region table You only search the result in the specified area. This area is the table type including four values {x, y, width, height}. The four values respectively represent the coordinate x, coordinate y, width, and height of the rectangular area. {100,100,200,200} is an example. If you do not want to specify the area, just input nil. NO nil
debug boolean If pass debug=true, it will produce a image ends with “-Debug.PNG” marked the matching areas. YES false

Return

Return Type Specification
locations table The coordinate of the first color matched in the found rectangular area, including { {x1, y1}, {x2, y2}, …}

Examples

-- Example 1:
local result = findColors({ {0x00ddff,0,0}, {0x00eeff,10,10}, {0x0000ff,0,20} }, 2, nil, true);
for i, v in pairs(result) do
    log(string.format("Found rect at: x:%f, y:%f", v[1], v[2]));
end

-- Example 2:
local colors = { {0x00ddff,0,0}, {0x00eeff,10,10}, {0x0000ff,0,20} };
local result = findColors(colors, 0, nil, true);
for i, v in pairs(result) do
    log(string.format("Found rect at: x:%f, y:%f", v[1], v[2]));
end

-- Example 3:
local colors = { {0x00ddff,0,0}, {0x00eeff,10,10}, {0x0000ff,0,20} };
local region = {100, 50, 200, 200};
local result = findColors(colors, 0, region);
for i, v in pairs(result) do
    log(string.format("Found rect at: x:%f, y:%f", v[1], v[2]));
end

findImage(targetImagePath, count, threshold, region, debug)

Search areas matching the specified image on current screen and return the center coordinates. It supports any format of target images. It also provides a debug mode which will produce an image marked the matching areas.

Imgur

Parameters

Parameter Type Specification Optional Default
targetImagePath String Relative path of the target image to match, for example: “images/gold.PNG”. Any valid foramt of images are supported. NO  
count integer How many areas to find. Pass 0 or nil if you don’t want to speficy the count. YES 0
threshold float Searching precision, maximum value is 1 means totally the same, minimum value is -1 means non same, default is 0.9, usually 0.99 is good. Pass nil if you just want to use the default value. YES 0.9
region table Do searching in which region. Pass nil if you just want to use the default value. YES Whole screen
debug boolean If pass debug=true, it will produce a image ends with “-Debug.PNG” marked the matching areas. YES false

Return

Return Type Specification
center locations table Center coordinates of the matching areas.

Examples

-- Example 1:
local result = findImage("images/Gold.PNG", 5, 0.99, nil, true)
for i, v in pairs(result) do
    log(string.format("Found rect at: x:%f, y:%f", v[1], v[2]));
end

-- Example 2:
local result = findImage("images/Gold.PNG", nil, nil, nil, true)
for i, v in pairs(result) do
    log(string.format("Found rect at: x:%f, y:%f", v[1], v[2]));
end

-- Example 3:
local result = findImage("images/Gold.PNG", 3)
for i, v in pairs(result) do
    log(string.format("Found rect at: x:%f, y:%f", v[1], v[2]));
end

-- Example 4:
local imagePath = "images/spirit.PNG";
local region = {100, 100, 300, 300};
local result = findImage(imagePath, 2, 0.98, region, true)
for i, v in pairs(result) do
    local x = v[1], y = v[2];

    log(string.format("Found rect at: x:%f, y:%f", x, y));
    
    -- Click the found location once.
    tap(x, y);
    usleep(16000);
end

screenshot(filePath, region)

Take a screenshot for the whole screen or specified area.

It will save the screenshot image as an PNG into “AutoTouch” album of iOS Photo Library if the filePath parameter is nill, and will save the PNG to the speficied path if filePath is not nil.

If region parameter is nil, it will take shot of the whole screen.

By Clicking “+” button at top-right of AutoTouch view, then “Copy Image Here”, you are able to copy an image from iOS Photo Library to AutoTouch scripts directory.

Parameters

Parameter Type Specification Optional Default
filePath string Where to save the image. YES “AutoTouch” album of iOS Photo Library
region table You make a screenshot of the specified area. This area is the table type including four values {x, y, width, height}. The four values respectively represent the coordinate x, coordinate y, width, and height of the rectangular area. {100,100,200,200} is an example. If you do not want to specify the area, just input nil. YES nil

Return

None

Examples

-- Take shot of the whole screen and save into  "AutoTouch" album of iOS Photo Library.
screenshot();

-- Take a screenshot of the whole screen and save to the specified path, if no PNG as path extension, .PNG will automatically added.
screenshot ("images/screenshot1");

-- Take a screenshot of the specified area and save.
screenshot ("images/screenshot2.PNG", {100, 100, 200, 200});

-- Take a screenshot of the specified area and save into  "AutoTouch" album of iOS Photo Library.
screenshot (nil, {100, 100, 200, 200});

appRun(appIdentifier)

Run specified application.

Parameters

Parameter Type Specification
appIdentifier string Application identifier, including “com.apple.mobilesafari”.

Return

None

Example

-- Run Safari
appRun("com.apple.mobilesafari");

appKill(appIdentifier)

Kill specified application.

Parameters

Parameter Type Specification
appIdentifier string Application identifier, including “com.apple.mobilesafari”.

Return

None

Example

-- Kill the running Safari
appKill("com.apple.mobilesafari");

appState(appIdentifier)

Get the running state of the specified application

Parameters

Parameter Type Specification
appIdentifier string Application identifier, including “com.apple.mobilesafari”.

Return

Return Type Specification
state string State of Character string type: “NOT RUNNING”, “ACTIVATED”, “DEACTIVATED”。

Example

-- Get the state of Safari.
local state = appState("com.apple.mobilesafari");
alert(string.format("State of Safari: %s", state));
-- Pop up the state of Safari: "ACTIVATED"

rootDir()

Get the default directory address of the saved script. This is the default saving address of scripts and screenshots: “/var/mobile/Library/AutoTouch/Scripts/”.

Parameters

None

Return

Return Type Specification
dir string Default directory address of the saved script.

Examples

local dirPath = rootDir();
alert(dirPath);
-- Popup "/var/mobile/Library/AutoTouch/Scripts/"

usleep(microseconds)

Sleep several microseconds (1/1000000)

Parameters

Parameter Type Specification
microseconds Integer The number of paused microseconds.

Return

None

Examples

-- Sleep 1 second.
usleep(1000000);

log(content)

Record log, can be seen in the log interface.

Parameters

Parameter Type Specification
content string The log content to be recorded.

Return

None

Examples

log("play here...");

alert(message)

Pop up the dialog box to show specified content.

Parameters

Parameter Type Specification
message string Content to be showed.

Return

None

Examples

alert("Hello World!");

toast(message, delay)

Show messages with Toast style and delay for some seconds.

Parameters

Parameter Type Specification
message string Content to be showed.
delay integer How long time to keep showing, default is 2 seconds.

Return

None

Examples

toast("Hello I'm a toast!", 5); -- Show message for 5 seconds.
toast("Hello again!"); -- Show message for 2 seconds.

vibrate()

Vibrate once.。

Parameters

None

Return

None

Examples

-- Vibrate once.
vibrate();

playAudio(audioFile, times)

Play audio document at specified location.

Parameters

Parameter Type Specification
audioFile string Absolute path of audio document.
times integer Number of repeated plays. 0 represents infinite repeat.

Return

None

Examples

-- Play audio infinitely.
playAudio("/var/audio.mp3", 0);

stopAudio()

Stop playing audio.

Parameters

None

Return

None

Examples

-- Stop playing audio.
stopAudio();

getOrientation()

Get orientation of the screen. Return the integer value. Please refer to the “Orientation Type of Screen” for specific correspondence relation.

Parameters

None

Return

Return Type Specification
orientation Integer Screen orientation may be these values

示例

local o = getOrientation();
alert(string.format("Screen orientation is : %d", 0))
-- Pop up the orientation 2 of the screen, and mark the reversed screen.

getScreenResolution()

Get screen resolution bese on pixels.

Parameters

None

Return

Return Type Specification
width Integer Width of screen resolution.
height Integer Height of screen resolution.

Examples

local w, h = getScreenResolution();
alert(string.format("Resolution of iPhone 6 Plus: width:%d, height:%d", w, h));
-- iPhone 6 Plus’s resolution width is 1242 and resolution height is 2208.

getSN()

Get Serial Number of the device.

Parameters

None

Return

Return Type Specification
SN string Serial Number of the device.

Examples

local sn = getSN();
alert(string.format("SN is : %s", sn));
-- Popup shows the SN of the device: C15NFK32TWD2

getVersion()

Get version of AutoTouch.

Parameters

None

Return

Return Type Specification
version string Version of AutoTouch.

Examples

local version = getVersion();
alert(string.format("Current version of AutoTouch is : %s", version));
-- Pop up shows current version of AutoTouch: 3.5.3-4

frontMostAppId()

Get identifier of current front most App.

Parameters

None

Return

Return Type Specification
App Identifier string App Identifier of current front most App.

Examples

local appId = frontMostAppId();
alert(string.format("Current front most App is : %s", appId));

frontMostAppOrientation()

Get orientation of current front most App. See the Types of orientations

Parameters

None

Return

Return Type Specification
Orientation integer Orientation of current front most App.

Examples

local orientation = frontMostAppOrientation();
alert(string.format("Orientation of current front most App is : %d", orientation));

intToRgb(intColor)

Transit integer color to independent values of R,G,B.

Parameters

Parameter Type Specification
intColor Integer Integer color value

Return

Return Type Specification
R Integer Red color value.
G Integer Green color value.
B Integer Blue color value.

Examples

local r, g, b = intToRgb(0x2b2b2b);
alert(string.format("R:%d, G:%d, B:%d", r, g, b));

rgbToInt(r, g, b)

Transit values of R,G,B to integer color value.

Parameters

Parameter Type Specification
R Integer Red color value.
G Integer Green color value.
B Integer Blue color value.

Return

Return Type Specification
intColor Integer Integer color value

Examples

local intColor = rgbToInt(200, 255, 100);
alert(string.format("Int type color: %d", intColor));

copyText(text)

Copy specified text to clipboard.

Parameters

Parameter Type Specification
text string Text to be copied.

Return

None

Examples

copyText("This is a copied text!");

clipText()

Get the text in the clipboard.

Parameters

None

Return

Return Type Specification
text string Text copied in the clipboard.

Examples

local text = clipText();
alert(text);
-- Popup shows the text to be copied: "This is a copied text!";

inputText(text)

Input text to the input box selected now. You can delete a character backspace by inputText(“\b”).

Parameters

Parameter Type Specification
text string Text to be input.

Return

None

Examples

inputText("Let's input some text automatically without tapping the keyboard!");
--  Delete 3 character by inputing 3 backspaces.
inputText("\b\b\b"); 

dialog(controls, enableRemember)

Pop up self-defined dialog box to accept the user input. Please refer to the example for specific usage.

Parameters

Parameter Type Specification
controls table Array of self-defined controls. You can now use these dialog box controls
enableRemember boolean Whether to use the “remember user’s input” function.

Return

None

Examples

local label = {type=CONTROLLER_TYPE.LABEL, text="Would you mind to provide some personal informations?"}
local nameInput = {type=CONTROLLER_TYPE.INPUT, title="Name:", key="Name", value="Kevin"}
local positionPicker = {type=CONTROLLER_TYPE.PICKER, title="Position:", key="Position", value="CEO", options={"CEO", "CTO", "CFO", "CXO"}}
local developerSwitch = {type=CONTROLLER_TYPE.SWITCH, title="A Developer:", key="ADeveloper", value=1}

local controls = {label, nameInput, positionPicker, developerSwitch}
local enableRemember = true;

-- Pop up the dialog box. After the popup, the script will suspend for user input until the user click “confirm” or “cancel”.
dialog(controls, enableRemember);

-- Then get the input value of user.
alert(string.format("name:%s, birthday:%s, gender:%d", nameInput.value, positionPicker.value, developerSwitch.value))

3.png-115.9kB

clearDialogValues(script)

Clear the remembered values of the dialog created by the function dialog.

Parameters

Parameter Type Specification
script string script path. eg. there is a dialog.lua script in the scripts list, use it like this: clearDialogValues(“dialog.lua”);

Return

None

Examples

-- There is a dialog.lua script in the scripts list
clearDialogValues("dialog.lua");

openURL(urlString)

Open url, or open other apps’ url scheme. Look at Always-Updated List of iOS App URL Scheme Names and example: Google Maps URL Scheme for iOS

Parameters

Parameter Type Specification
urlString string Target to open.

Return

None

Examples

openURL("https://autotouch.net")
openURL("prefs:root=General&path=About")
openURL("musics://")
openURL("itms-apps://itunes.apple.com")
openURL("tel://+1123456")
openURL("clashofclans://")

isLicensed()

Check if the current device is running licensed AutoTouch

Parameters

None

Return

Return Type Specification
licensed boolean If current device is licensed.

Examples

if isLicensed() then
    alert("Your device is licensed by AutoTouch!");
end

HTTP APIs

There is a series of HTTP APIs for AutoTouch controlling in Local Area Netowork, they are the same APIs Web Server in AutoTouch Settings is using.

Play a script

GET /control/start_playing?path=/scriptPath

Parameters

Parameter Specification
path Script path.

Return

Successful:

{
    "status": "success"
}

Failed:

{
    "status": "fail",
    "info": ""
}

Examples

HTTP GET http://192.168.1.99:8080/control/start_playing?path=/scriptPath
{
    "status": "fail",
    "info": "Script doesn't exist."
}

Stop playing a script

GET /control/stop_playing?path=/scriptPath

Parameters

Parameter Specification
path Script path.

Return

Successful:

{
    "status": "success"
}

Failed:

{
    "status": "fail",
    "info": ""
}

Examples

HTTP GET http://192.168.1.99:8080/control/start_playing?path=/scriptPath
{
    "status": "fail",
    "info": "Script doesn't exist."
}

List files in a directory

GET /files?path=/Records

Parameters

Parameter Specification
path Directory path to list.

Return

{
    "files": [
        {
            "filePath": "",
            "fileSize": "",
            "iconName": ""
        },
        ...
    ]
}

Examples

HTTP GET http://192.168.1.99:8080/files?path=/Records
{
    "files": [
        {
            "filePath": "/Records/2019-03-10: 12:00:00.lua",
            "fileSize": "12kb",
            "iconName": "script"
        },
        ...
    ]
}

Create a new directory

GET /file/newFolder?path=/Test

Parameters

Parameter Specification
path New Directory path to create.

Return

Successful:

{
    "status": "success"
}

Failed:

{
    "status": "fail",
    "info": ""
}

Examples

HTTP GET http://192.168.1.99:8080/file/newFolder?path=/Test
{
    "status": "success"
}

Create a new file

GET /file/new?path=/newFilePath

Parameters

Parameter Specification
path New file path to make.

Return

Successful:

{
    "status": "success"
}

Failed:

{
    "status": "fail",
    "info": ""
}

Examples

HTTP GET http://192.168.1.99:8080/file/new?path=/newFilePath
{
    "status": "fail",
    "info": "Invalid file path"
}

Delete a file

GET /file/delete?path=/filePathToDelete

Parameters

Parameter Specification
path File path to delete.

Return

Successful:

{
    "status": "success"
}

Failed:

{
    "status": "fail",
    "info": ""
}

Examples

HTTP GET http://192.168.1.99:8080/file/delete?path=/filePathToDelete
{
    "status": "fail",
    "info": "Invalid file path"
}

Rename a file or directory

GET /file/rename?path=/oldFilePath&newPath=newFilePath

Parameters

Parameter Specification
path Old path.
newPath New path.

Return

Successful:

{
    "status": "success"
}

Failed:

{
    "status": "fail",
    "info": ""
}

Examples

HTTP GET http://192.168.1.99:8080/file/rename?path=/oldFilePath&newPath=newFilePath
{
    "status": "fail",
    "info": "Invalid file path"
}

Constants

Types of physical keys

Value Specification
KEY_TYPE.HOME_BUTTON Home Button
KEY_TYPE.VOLUME_DOWN_BUTTON Volume – Button
KEY_TYPE.VOLUME_UP_BUTTON Volume + Button
KEY_TYPE.POWER_BUTTON Power Button

Types of dialog controls

Value Specification
CONTROLLER_TYPE.LABEL Text label
CONTROLLER_TYPE.INPUT Input box
CONTROLLER_TYPE.PICKER Picker
CONTROLLER_TYPE.SWITCH Switch

Types of screen orientations

Value Specification
ORIENTATION_TYPE.UNKNOWN Unknown orientation. Practical value is 0.
ORIENTATION_TYPE.PORTRAIT Portrait screen. Home button is at the bottom. Practical value is 1.
ORIENTATION_TYPE.PORTRAIT_UPSIDE_DOWN Upside-down portrait screen. Home button on the top. Practical value is 2.
ORIENTATION_TYPE.LANDSCAPE_LEFT Landscape left screen. Home Key is in the left. Practical value is 3.
ORIENTATION_TYPE.LANDSCAPE_RIGHT Landscape right screen. Home key is in the right. Practical value is 4.