touch Sample Code
Examples
-- One-liner style:
touch.on(306, 300):step_len(2):step_delay(0):move(350, 800):msleep(1000):off()
--
-- Expanded style:
touch.on(306, 300) -- touch at 306,300
:step_len(2) -- set step length to 2
:step_delay(0) -- set per-step delay to 0
:move(350, 800) -- move to 350,800 with the above settings
:msleep(1000) -- wait 1000 ms (1 second)
:off() -- lift finger
--
-- Using a variable:
local te = touch.on(306,300)
te:step_len(2)
te:step_delay(0)
te:move(350, 800)
te:msleep(1000)
te:off()
--
-- Typical slide sequence:
touch.on(306, 300)
:move(350, 800)
:msleep(1000)
:off()
--
-- Equivalent one-liner:
touch.on(306, 300):move(350, 800):msleep(1000):off()
--
-- Simulate a tap using on+delay+off:
touch.on(306, 300):msleep(30):off()
--
Tips for fast and precise swipes
-- A more stable fast-and-precise swipe is usually done like this:
-- quickly go a bit past the target, then move back to the target
touch.on(125, 2000) -- press at start position
:step_len(10) -- longer step for a fast swipe
:step_delay(1) -- 1ms per step for fast movement
:move(125, 505 - 20) -- quickly move slightly past the target (upward swipe => smaller y)
:step_len(1) -- shorten the step length when moving back to reduce inertia
:step_delay(20) -- slow down a bit when moving back for a steadier path
:move(125, 505) -- move back to the target position
:delay(200) -- wait before lifting
:off() -- lift finger
- The example above is for an upward swipe. For downward, leftward, or rightward swipes, make the “past the target” point slightly beyond the target in that direction.
- If the swipe does not involve a screen edge, usually moving a bit past the target and then moving back to the target is already precise, fast, and free of inertia.
- If that “past the target” point would be outside the screen, that part does not count. In that case, swipe quickly to the screen edge first, then pull back a little, and finally move slowly to the target position.
- Even if the target itself is right on the screen edge, it is still usually more stable to reach the edge first, pull back a little, and then slowly move back to the target.