module Eagle::Script

Overview

Schedules synthetic input over time: key presses, clicks, drags and gamepad events.

Scripts drive integration tests, attract-mode demos and replays. Events go through exactly the same path as real input, so Input, App#input and every node see them. Times are seconds since the first step was scheduled.

Script.at(0.5) { Script.click(v2(100, 100)) }
Script.at(1.0) { Script.type("hello"); Script.key(Key::Enter) }
Script.drag(v2(10, 10), v2(200, 200), seconds: 0.5, start: 2.0)
Script.hold(Key::Right, 1.5, start: 3.0) # walk right for a moment

Defined in:

eagle/core/script.cr

Class Method Summary

Class Method Detail

def self.at(seconds : Number, &block : -> ) : Nil #

Runs the block when the script clock reaches seconds.


def self.clear : Nil #

Cancels every pending step and resets the clock.


def self.click(at : Vec2, button : MouseButton = MouseButton::Left, clicks : Int32 = 1) : Nil #

Moves the mouse to at and clicks. Pass clicks: 2 for a double-click.


def self.connect_gamepad(id : Int32 = 0) : Nil #

Simulates plugging in a gamepad.


def self.drag(from : Vec2, to : Vec2, seconds : Number = 0.5, start : Number = 0, steps : Int32 = 10, button : MouseButton = MouseButton::Left) : Nil #

Schedules a full drag: press at from, move in steps increments over seconds, then release at to. Starts at script time start.


def self.drop_file(path : String) : Nil #

Simulates dropping a file onto the window.


def self.gamepad_axis(id : Int32, axis : GamepadAxis, value : Number) : Nil #

Moves a gamepad axis to value (-1 to 1).


def self.gamepad_button(id : Int32, b : GamepadButton) : Nil #

Presses and releases a gamepad button.


def self.hold(k : Key, seconds : Number, start : Number = 0) : Nil #

Holds a key down for seconds, starting at script time start.


def self.key(k : Key, mods : KeyMod = KeyMod::None) : Nil #

--- convenience emitters (queue events for the next frame) --- Presses and releases a key on the next frame.


def self.key_down(k : Key, mods : KeyMod = KeyMod::None) : Nil #

Presses a key and keeps it held until .key_up.


def self.key_up(k : Key, mods : KeyMod = KeyMod::None) : Nil #

Releases a key.


def self.move(to : Vec2) : Nil #

Moves the mouse to to.


def self.pending : Int32 #

Number of steps still waiting to run.


def self.press(at : Vec2, button : MouseButton = MouseButton::Left) : Nil #

Moves to at and presses a mouse button without releasing it.


def self.release(at : Vec2, button : MouseButton = MouseButton::Left) : Nil #

Moves to at and releases a mouse button.


def self.running? : Bool #

True while steps remain.


def self.time : Float64 #

Seconds since the script started.


def self.type(text : String) : Nil #

Types text, as if entered on the keyboard.


def self.wheel(delta : Vec2, at : Vec2 = Input.mouse) : Nil #

Scrolls the wheel by delta.