Skip to content
Anthony Headley edited this page Apr 27, 2020 · 1 revision

Touch(int, string, touchID, absX, absY) : nil

Brief:

⚠ Be very careful with this API as it is very easy to press something you don't expect or to make the console unresponsive by forgetting to release. ⚠

Allows you to mimic the user tapping the screen. Screen Coordinates are based on the top left hand corner being absX/Y == 0/0

The absolute X and Y positions are based on screen space, so the coordinates for the menu button on a console and on PC will be different if the OS menu bar is showing, the display is a different size or, the application window is not full screen onPC.

Paramiters:

Name Type Description Optional
dsiplayIndex int The display you want to touch
type string "press", "move", "release"
touchID int ⚠ Not sure if this means finger index (1= index, 2=middle), or number of fingers, or something else.
absX int X Position
absY int Y Position

Returns:

Type Description
nil

Examples:

    local consoleType = HostSubType()
    Echo(consoleType)
    if consoleType ~= "Light" and consoleType ~= "Full" then
        -- this will may work onPC an I'm not sure about other devices
        Echo("Not Light or Full, Exitting")
        return
    end

    -- build of a table of moves
    --[[
        The table holds the instructions we want to send to Touch().
        The below coordinates a assume a few things:
        1. The Display is 1920 x 1080
        2. Show Control Bar (the left one) is hidden
        3. The Encoder bar is not shown.
        4. The Command Line bar is shown.
    ]] 
    local moves = {
        -- expand Show Control Bar
        {"Expand", 25, 1055, "press"},
        {"Expand", 25, 1055, "release"},
        -- press menu button
        {"Menu", 25, 100, "press"},
        {"Menu", 25, 100, "release"},
        -- delete this screen
        {"Delete This Screen", 1700, 666, "press"},
        {"Delete This Screen", 1700, 666, "release"},
        -- contract Show Control Bar
        {"Contract", 25, 1055, "press"},
        {"Contract", 25, 1055, "release"},
        -- box the top left
        {"NW-Start", 0, 0, "press"},
        {"NW-Move", 1700, 900, "move"},
        {"NW-End", 1700, 900, "release"},
        -- press the common tab
        {"Common", 650, 320, "press"},
        {"Common", 650, 320, "release"},
        -- press the layout view button
        {"Fixture", 840, 444, "press"},
        {"Fixture", 840, 444, "release"},
        -- Add Layout Pool
        {"New Layouts", 50, 980, "press"},
        {"New Layouts", 50, 980, "release"},
        -- Pools Tab
        {"Pools Tab", 800, 320, "press"},
        {"Pools Tab", 800, 320, "release"},
        -- Layout Pools
        {"Pools Pool", 670, 500, "press"},
        {"Pools Pool", 670, 500, "release"},
        -- Add Worlds Pool
        {"New Worlds", 1770, 50, "press"},
        {"New Worlds", 1770, 50, "release"},
        -- Worlds
        {"Worlds", 670, 620, "press"},
        {"Worlds", 670, 620, "release"},
    }

    -- Now lets touch some screens
    for key, value in pairs(moves) do
        -- Tell me what you are doing
        Echo("%s-%s at %d, %d", value[1], value[4], value[2], value[3])
        -- Actually do it
        Touch(1, value[4], 1, value[2], value[3]) -- Touch(1, "press", 1, 670, 620)
        coroutine.yield(1/60) -- wait a moment.
    end

    -- ⚠ two finger either doesnt work or I'm using it wrong.
    -- place fingers 100 px apart
    Touch(1,"press", 1, 910, 1770)
    Touch(1,"press", 2, 1010, 1770)
    -- scroll left
    for i = 959, 300, -10 do
        Touch(1, "move", 1, i - 50, 1770) -- Finger 1?
        Touch(1, "move", 2, i + 50, 1770) -- Finger 2?
        --coroutine.yield(1/60) -- wait a moment.
        Echo("<<"..i)
    end
    -- scroll Right
    for i = 300, 960, 10 do
        Touch(1, "move", 1, i - 50, 1770) -- Finger 1?
        Touch(1, "move", 2, i + 50, 1770) -- Finger 2?
        --coroutine.yield(1/60) -- wait a moment.
        Echo(">" .. i)
    end
    Touch(1,"release", 1, 910, 1770)
    Touch(1,"release", 2, 1010, 1770)
Clone this wiki locally