Skip to contents

Keeps the computer awake by moving the mouse cursor and clicking periodically with a human-like behavior. It automatically detects the operating system (Windows or macOS) and runs the appropriate underlying logic.

Usage

dont_sleep(sec_range = c(20, 60), off_time = 18.5, quiet = FALSE)

Arguments

sec_range

Numeric vector of length 2. Range (in seconds) of random intervals between mouse movements and clicks. Default is c(20, 60).

off_time

Numeric. Decimal hour (24h format) to stop the function automatically, e.g. 18.5 means 18:30 (6:30 PM). Default is 18.5.

quiet

Logical. If TRUE, suppresses progress messages. Default is FALSE.

Value

Invisibly returns NULL when the function exits.

Details

The cursor initially moves to the upper-left corner (0,0), then performs small random movements and clicks periodically to avoid system sleep. The function exits if the user moves the mouse away from the corner or when the specified off-time is reached.

Requires cliclick installed on macOS (install via Homebrew: brew install cliclick), and the KeyboardSimulator package on Windows.

Examples

if (FALSE) { # \dontrun{
# Keep the computer awake until 8:00 PM, with mouse actions every 30 to 60 seconds
dont_sleep(sec_range = c(30, 60), off_time = 20)
} # }