Skip to content

auto #

Cross-Platform mouse and keyboard manipulation.

Cross-platform tool to manipulate the mouse and keyboard to automate tasks.

import auto
import time

fn main() {
    // get current mouse position
    x, y := auto.Mouse.get_pos()
    println('Mouse is at: X: ${x}, Y: ${y}')

    // get the dimensions of the primary display
    sz := auto.Screen.size()

    // center the mouse in the middle of the screen
    auto.Mouse.set_pos(sz.width / 2, sz.height / 2)

    // left and right click the mouse
    auto.Mouse.click(.left)
    auto.Mouse.click(.right)

    // double left click
    auto.Mouse.double_click()

    // click and drag mouse to 100, 150
    auto.Mouse.drag_to(100, 150, button: .left, duration: time.second)

    // emulate keyboard typing
    auto.Keyboard.press(.s)
    auto.Keyboard.write('some message to write', speed: 100 * time.millisecond)
}

fn KeyCode.from_byte #

fn KeyCode.from_byte(c u8) ?(KeyCode, KeyModifier)

KeyCode.from_byte returns the KeyCode and KeyModifier for an ascii character.

fn Keyboard.press #

fn Keyboard.press(key_code KeyCode, mod KeyModifier)

Keyboard.press triggers a key press.

fn Keyboard.write #

fn Keyboard.write(str string, params KeyboardWriteParams)

Keyboard.write types out a string.

fn Mouse.click #

fn Mouse.click(button Button)

Mouse.click triggers a mouse click event at the current mouse cursor position.

fn Mouse.double_click #

fn Mouse.double_click(button Button)

Mouse.double_click triggers a double click event at the current mouse cursor position.

fn Mouse.drag_rel #

fn Mouse.drag_rel(rel_x int, rel_y int, params DragParams)

Mouse.drag_rel drags the mouse cursor relative to the current location of the mouse.

fn Mouse.drag_to #

fn Mouse.drag_to(target_x int, target_y int, params DragParams)

Mouse.drag_to moves the the mouse cursor while holding down a mouse button.

fn Mouse.get_pos #

fn Mouse.get_pos() (int, int)

Mouse.get_pos returns the global X and Y coordinates of the mouse cursor. Returns -1, -1 if there is an error getting the mosue position.

fn Mouse.get_pos_opt #

fn Mouse.get_pos_opt() ?(int, int)

Mouse.get_pos_opt returns the global X and Y coordinates of the mouse cursor.

fn Mouse.set_pos #

fn Mouse.set_pos(x int, y int)

Mouse.set_pos immediately moves the mouse cursor to the x, y.

fn Screen.compositor #

fn Screen.compositor() Compositor

Screen.get_compositor gets whether or not a user has X11 or Wayland as their window compositor.

fn Screen.refresh_rate #

fn Screen.refresh_rate() ?int

Screen.refresh_rate returns the screen refresh rate of the primary display.

fn Screen.size #

fn Screen.size() Size

Screen.size returns the size of the primary display.

enum Button #

enum Button {
	left
	right
	middle
}

Button is the buttons on a mouse or touchpad.

enum Compositor #

enum Compositor {
	unknown
	wayland
	x11
	quartz
	windows
}

Compositor is the window compositor being used by the system.

enum KeyCode #

@[_allow_multiple_values]
enum KeyCode {
	a             = keycode_a
	b             = keycode_b
	c             = keycode_c
	d             = keycode_d
	e             = keycode_e
	f             = keycode_f
	g             = keycode_g
	h             = keycode_h
	i             = keycode_i
	j             = keycode_j
	k             = keycode_k
	l             = keycode_l
	m             = keycode_m
	n             = keycode_n
	o             = keycode_o
	p             = keycode_p
	q             = keycode_q
	r             = keycode_r
	s             = keycode_s
	t             = keycode_t
	u             = keycode_u
	v             = keycode_v
	w             = keycode_w
	x             = keycode_x
	y             = keycode_y
	z             = keycode_z
	_0            = keycode_0
	_1            = keycode_1
	_2            = keycode_2
	_3            = keycode_3
	_4            = keycode_4
	_5            = keycode_5
	_6            = keycode_6
	_7            = keycode_7
	_8            = keycode_8
	_9            = keycode_9
	space         = keycode_space
	semicolon     = keycode_semicolon
	comma         = keycode_comma
	period        = keycode_period
	slash         = keycode_slash
	backtick      = keycode_backtick
	left_bracket  = keycode_left_bracket
	right_bracket = keycode_right_bracket
	backslash     = keycode_backslash
	quote         = keycode_quote
	hyphen        = keycode_hyphen
	equals        = keycode_equals
	return        = keycode_return
	enter         = keycode_return
	backspace     = keycode_backspace
	tab           = keycode_tab
	left_shift    = keycode_left_shift
	right_shift   = keycode_right_shift
	left_ctrl     = keycode_left_ctrl
	right_ctrl    = keycode_right_ctrl
	left_alt      = keycode_left_alt
	right_alt     = keycode_right_alt
	escape        = keycode_escape
	f1            = keycode_f1
	f2            = keycode_f2
	f3            = keycode_f3
	f4            = keycode_f4
	f5            = keycode_f5
	f6            = keycode_f6
	f7            = keycode_f7
	f8            = keycode_f8
	f9            = keycode_f9
	f10           = keycode_f10
	f11           = keycode_f11
	f12           = keycode_f12
	left_arrow    = keycode_left_arrow
	right_arrow   = keycode_right_arrow
	up_arrow      = keycode_up_arrow
	down_arrow    = keycode_down_arrow
	delete        = keycode_delete
}

KeyCode is a key on a keyboard.

enum KeyModifier #

@[flag]
enum KeyModifier {
	shift
	ctrl
	alt
}

KeyModifier is a key which can be pressed in combination with another key.

struct DragParams #

@[params]
struct DragParams {
__global:
	duration time.Duration = time.millisecond * 750
	button   Button        = .left
}

DragParams are the options for determining how the mouse is dragged across the screen.

struct Keyboard #

@[noinit]
struct Keyboard {}

Keyboard acts as a namespace for keyboard related functions.

struct KeyboardWriteParams #

@[params]
struct KeyboardWriteParams {
__global:
	speed time.Duration = 50 * time.millisecond
}

KeyboardWriteParams is the parameters for determining how Keyboard.write behaves.

struct Mouse #

@[noinit]
struct Mouse {}

Mouse acts as a namespace for mouse related functions.

struct Pos #

struct Pos {
__global:
	x int
	y int
}

Pos is the X and Y coordinates on a screen.

struct Screen #

@[noinit]
struct Screen {}

Screen acts as a namespace for screen related functions.

struct Size #

struct Size {
__global:
	width  int
	height int
}

Size is the width and height of a screen.