Module screen.lua
Screen interaction and observation helpers
Functions
| screen.contains (pix) | Check if the screen contains a pixel/set of pixels | 
| screen.hold (x, y, seconds) | Hold a finger on the screen | 
| screen.hold_if (condition, to_hold) | Hold the screen if a pixel/set of pixels is visible | 
| screen.hold_until (condition, to_hold) | Hold the screen until a pixel/set of pixels is visible | 
| screen.hold_while (condition, to_hold) | Hold the screen while a pixel/set of pixels is visible | 
| screen.tap (x, y, times, interval) | Tap the screen | 
| screen.tap_fast (x, y, times, fingers) | Tap the screen quickly with multiple fingers. | 
| screen.tap_if (condition, to_tap) | Tap the screen if a pixel/set of pixels is visible | 
| screen.tap_until (condition, to_tap) | Tap the screen until a pixel/set of pixels is visible | 
| screen.tap_while (condition, to_tap) | Tap the screen while a pixel/set of pixels is visible | 
| screen.swipe (start_, end_, speed) | Swipe the screen. | 
| screen.wait (condition) | Wait until a pixel/set of pixels is visible | 
Tables
| screen.edge | Pixels on the corners of the screen | 
| screen.mid | Pixels centered on various locations on the screen | 
Fields
| screen.check_interval | Number of microseconds after which the screen is checked for updates | 
| screen.hold_duration | Number of seconds to hold a finger on the screen by default | 
| screen.tap_interval | Number of microseconds between each consecutive tap | 
| screen.wait_before_action | Number of seconds to wait before each action (tap_if, tap_until, ...) | 
| screen.wait_after_action | Number of seconds to wait after each action (tap_if, tap_until, ...) | 
| screen.wait_before_tap | Number of seconds to wait before each tap | 
| screen.wait_after_tap | Number of seconds to wait after each tap | 
| screen.debug | Print detailed information about taps, swipes and checks | 
| screen.width | Width of screen from getScreenResolution (not writable) | 
| screen.height | Height of screen from getScreenResolution (not writable) | 
Contexts
| screen.action_context | Context manager for screen actions and checking | 
| screen.tap_context | Context manager for tapping | 
| screen.hold_context | Context manager for holding down a finger the screen | 
Listeners
| screen.before_action (func) | Register a function to be run before an action (tap_if, tap_until, ...) | 
| screen.after_action (func) | Register a function to be run after an action (tap_if, tap_until, ...) | 
| screen.before_check (func) | Register a function to be run before the screen is checked for updates | 
| screen.after_check (func) | Register a function to be run after the screen is checked for updates | 
| screen.before_tap (func) | Register a function to be run before a finger touches the screen | 
| screen.after_tap (func) | Register a function to be run after a finger touches the screen | 
| screen.on_nth_check (n, func) | Register a function to be run after a number of consecutive screen checks | 
Functions
- screen.contains (pix)
- 
    Check if the screen contains a pixel/set of pixels
    Parameters:- pix pixel.Pixel or pixel.Pixels Pixel(s) instance to check position(s) of
 Returns:- 
           boolean
        does the screen contain the pixel(s)
    
 
- screen.hold (x, y, seconds)
- 
    Hold a finger on the screen
    Parameters:- x number or pixel.Pixel x-position/pixel(s) to hold
- y int (optional) y position to hold
- seconds number (optional) Number of seconds to hold finger on the screen (default: 0.5s)
 Returns:- 
           screen
        screen for method chaining
    
 Usage:-- hold x=10, y=10 for 0.5 seconds screen.hold(10, 10, 0.5) -- or screen.hold(Pixel(10, 10), 0.5) 
- screen.hold_if (condition, to_hold)
- 
    Hold the screen if a pixel/set of pixels is visible
    Parameters:- condition pixel.Pixel, pixel.Pixels or func condition to hold if
- to_hold pixel.Pixel (optional) pixel to hold
 Returns:- 
           screen
        screen for method chaining
    
 See also:
- screen.hold_until (condition, to_hold)
- 
    Hold the screen until a pixel/set of pixels is visible
    Parameters:- condition pixel.Pixel, pixel.Pixels or func condition to hold until
- to_hold pixel.Pixel (optional) pixel to hold
 Returns:- 
           screen
        screen for method chaining
    
 See also:
- screen.hold_while (condition, to_hold)
- 
    Hold the screen while a pixel/set of pixels is visible
    Parameters:- condition pixel.Pixel, pixel.Pixels or func condition to hold while
- to_hold pixel.Pixel (optional) pixel to hold
 Returns:- 
           screen
        screen for method chaining
    
 See also:
- screen.tap (x, y, times, interval)
- 
    Tap the screen
    Parameters:- x pixel.Pixel or int x-position or pixel to tap
- y int (optional) y-position to tap
- times int (optional) number of times to tap
- interval number (optional) interval (in seconds) between taps
 Returns:- 
           screen
        screen for method chaining
    
 Usage:-- tap x=10, y=10 twice and wait 1 second between taps screen.tap(10, 10, 2, 1) -- or screen.tap(Pixel(10, 10), 2, 1) 
- screen.tap_fast (x, y, times, fingers)
- 
    Tap the screen quickly with multiple fingers.
 With multitouch, more fingers mean more taps/sec.
 Tap speed: approx. 50 taps/sec per fingerParameters:- x number, pixel.Pixel or table x-position/pixel(s) to tap
- y int (optional) y position to tap (not required if x is not a number)
- times
            int, pixel.Pixel or func
         (optional) - Number of taps per finger (total taps: n * fingers)
- Pixel that when visible stops tapping
- Function that returns true when tapping should stop
 
- fingers int (optional) number of fingers to use
 Returns:- 
           screen
        screen for method chaining
    
 Usage:-- tap x=10, y=10 twice with 2 fingers (4 total taps) screen.tap_fast(10, 10, 2, 2) -- or screen.tap_fast(Pixel(10, 10), 2, 2) -- tap each position with a unique finger twice (4 total taps) screen.tap_fast({{x=10, y=10}, {x=20, y=20}}, 2) -- or screen.tap_fast(Pixels{{10, 10}, {20, 20}}, 2) -- tap x=10, y=10 with 2 fingers until x=20, y=20 is red local check_pixel = Pixel(20, 20, colors.red) screen.tap_fast(10, 10, check_pixel, 2) -- or screen.tap_fast(Pixel(10, 10), check_pixel, 2) -- tap x=10, y=10 with 2 fingers a random number of times local check_func = function() return math.random() < 0.3 end screen.tap_fast(10, 10, check_func, 2) -- or screen.tap_fast(Pixel(10, 10), check_func, 2) 
- screen.tap_if (condition, to_tap)
- 
    Tap the screen if a pixel/set of pixels is visible
    Parameters:- condition pixel.Pixel, pixel.Pixels or func pixel(s) to search for or a function that returns true if tapping is required
- to_tap pixel.Pixel (optional) pixel to tap
 Returns:- 
           screen
        screen for method chaining
    
 Usage:-- tap x=10, y=10 if x=10, y=10 is red screen.tap_if(Pixel(10, 10, colors.red)) -- tap x=50, y=50 if x=10, y=10 is red screen.tap_if(Pixel(10, 10, colors.red), Pixel(50, 50)) -- tap x=50, y=50 if x=10, y=10 is red AND x=20, y=20 is red screen.tap_if(Pixels{{10, 10, colors.red}, {20, 20, colors.red}}, Pixel(50, 50)) -- tap x=50, y=50 if function returns true function needs_tap() return true end screen.tap_if(needs_tap, Pixel(50, 50)) 
- screen.tap_until (condition, to_tap)
- 
    Tap the screen until a pixel/set of pixels is visible
    Parameters:- condition pixel.Pixel, pixel.Pixels or func condition to tap until
- to_tap pixel.Pixel (optional) pixel to tap
 Returns:- 
           screen
        screen for method chaining
    
 See also:
- screen.tap_while (condition, to_tap)
- 
    Tap the screen while a pixel/set of pixels is visible
    Parameters:- condition pixel.Pixel, pixel.Pixels or func condition to tap while
- to_tap pixel.Pixel (optional) pixel to tap
 Returns:- 
           screen
        screen for method chaining
    
 See also:
- screen.swipe (start_, end_, speed)
- 
    Swipe the screen.
 
 Possible string arguments are:- left, right, top, bottom, center
- top_left, top_right, bottom_left, bottom_right
 Parameters:- start_ pixel.Pixel or string pixel at which to start the swipe
- end_ pixel.Pixel or string pixel at which to end the swipe
- speed int swipe speed (1-10)
 Returns:- 
           screen
        screen for method chaining
    
 
- screen.wait (condition)
- 
    Wait until a pixel/set of pixels is visible
    Parameters:- condition pixel.Pixel, pixel.Pixels or func condition to wait for
 Returns:- 
           screen
        screen for method chaining
    
 See also:
Tables
- screen.edge
- 
    Pixels on the corners of the screen
    Fields:- top_left x = 0, y = 0
- top_right x = screen.width, y = 0
- bottom_left x = 0, y = screen.height
- bottom_right x = screen.width, y = screen.height
 
- screen.mid
- 
    Pixels centered on various locations on the screen
    Fields:- left x = 0, y = screen.height / 2
- right x = screen.width, y = screen.height / 2
- top x = screen.width / 2, y = 0
- bottom x = screen.width / 2, y = screen.height
- center x = screen.width / 2, y = screen.height / 2
 
Fields
- screen.check_interval
- Number of microseconds after which the screen is checked for updates
- screen.hold_duration
- Number of seconds to hold a finger on the screen by default
- screen.tap_interval
- Number of microseconds between each consecutive tap
- screen.wait_before_action
- Number of seconds to wait before each action (tap_if, tap_until, ...)
- screen.wait_after_action
- Number of seconds to wait after each action (tap_if, tap_until, ...)
- screen.wait_before_tap
- Number of seconds to wait before each tap
- screen.wait_after_tap
- Number of seconds to wait after each tap
- screen.debug
- Print detailed information about taps, swipes and checks
- screen.width
- Width of screen from getScreenResolution (not writable)
- screen.height
- Height of screen from getScreenResolution (not writable)
Contexts
- screen.action_context
- 
    Context manager for screen actions and checking
    - condition
 
- screen.tap_context
- Context manager for tapping
- screen.hold_context
- 
    Context manager for holding down a finger the screen
    - x int or pixel.Pixel
- y int (optional)
 
Listeners
- screen.before_action (func)
- 
    Register a function to be run before an action (tap_if, tap_until, ...)
    Parameters:- func func function to run before action (no arguments)
 
- screen.after_action (func)
- 
    Register a function to be run after an action (tap_if, tap_until, ...)
    Parameters:- func func function to run after action (no arguments)
 
- screen.before_check (func)
- 
    Register a function to be run before the screen is checked for updates
    Parameters:- func func function to run before check (no arguments)
 
- screen.after_check (func)
- 
    Register a function to be run after the screen is checked for updates
    Parameters:- func func function to run after check (no arguments)
 
- screen.before_tap (func)
- 
    Register a function to be run before a finger touches the screen
    Parameters:- func func function to run before tap (no arguments)
 
- screen.after_tap (func)
- 
    Register a function to be run after a finger touches the screen
    Parameters:- func func function to run after tap (no arguments)
 
- screen.on_nth_check (n, func)
- 
    Register a function to be run after a number of consecutive screen checks
    Parameters:- n int or table number of checks to execute before calling function
- func func function to run after n consecutive checks