auto #
Cross-Platform mouse and keyboard manipulation.
Cross-platform tool to manipulate the mouse and keyboard to automate tasks.
import auto
75 | import time
76 |
77 | fn main() {
78 | // get current mouse position
79 | x, y := auto.Mouse.get_pos()
80 | println('Mouse is at: X: ${x}, Y: ${y}')
81 |
82 | // get the dimensions of the primary display
83 | sz := auto.Screen.size()
84 |
85 | // center the mouse in the middle of the screen
86 | auto.Mouse.set_pos(sz.width / 2, sz.height / 2)
87 |
88 | // left and right click the mouse
89 | auto.Mouse.click(.left)
90 | auto.Mouse.click(.right)
91 |
92 | // double left click
93 | auto.Mouse.double_click()
94 |
95 | // click and drag mouse to 100, 150
96 | auto.Mouse.drag_to(100, 150, button: .left, duration: time.second)
97 |
98 | // emulate keyboard typing
99 | auto.Keyboard.press(.s)
100 | auto.Keyboard.write('some message to write', speed: 100 * time.millisecond)
101 | }
102 |
103 | fn KeyCode.from_byte #
108 | fn KeyCode.from_byte(c u8) ?(KeyCode, KeyModifier)
109 | KeyCode.from_byte returns the KeyCode and KeyModifier for an ascii character.
110 | 111 |fn Keyboard.press #
116 | fn Keyboard.press(key_code KeyCode, mod KeyModifier)
117 | Keyboard.press triggers a key press.
118 | 119 |fn Keyboard.write #
124 | fn Keyboard.write(str string, params KeyboardWriteParams)
125 | Keyboard.write types out a string.
126 | 127 |fn Mouse.click #
132 | fn Mouse.click(button Button)
133 | Mouse.click triggers a mouse click event at the current mouse cursor position.
134 | 135 |fn Mouse.double_click #
140 | fn Mouse.double_click(button Button)
141 | Mouse.double_click triggers a double click event at the current mouse cursor position.
142 | 143 |fn Mouse.drag_rel #
148 | fn Mouse.drag_rel(rel_x int, rel_y int, params DragParams)
149 | Mouse.drag_rel drags the mouse cursor relative to the current location of the mouse.
150 | 151 |fn Mouse.drag_to #
156 | fn Mouse.drag_to(target_x int, target_y int, params DragParams)
157 | Mouse.drag_to moves the the mouse cursor while holding down a mouse button.
158 | 159 |fn Mouse.get_pos #
164 | fn Mouse.get_pos() (int, int)
165 | 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.
166 | 167 |fn Mouse.get_pos_opt #
172 | fn Mouse.get_pos_opt() ?(int, int)
173 | Mouse.get_pos_opt returns the global X and Y coordinates of the mouse cursor.
174 | 175 |fn Mouse.set_pos #
180 | fn Mouse.set_pos(x int, y int)
181 | Mouse.set_pos immediately moves the mouse cursor to the x, y.
fn Screen.compositor #
188 | fn Screen.compositor() Compositor
189 | Screen.get_compositor gets whether or not a user has X11 or Wayland as their window compositor.
190 | 191 |fn Screen.refresh_rate #
196 | fn Screen.refresh_rate() ?int
197 | Screen.refresh_rate returns the screen refresh rate of the primary display.
198 | 199 |fn Screen.size #
204 | fn Screen.size() Size
205 | Screen.size returns the size of the primary display.
206 | 207 |enum Button #
212 | enum Button {
213 | left
214 | right
215 | middle
216 | }
217 | Button is the buttons on a mouse or touchpad.
218 | 219 |enum Compositor #
224 | enum Compositor {
225 | unknown
226 | wayland
227 | x11
228 | quartz
229 | windows
230 | }
231 | Compositor is the window compositor being used by the system.
232 | 233 |enum KeyCode #
239 | enum KeyCode {
240 | a = keycode_a
241 | b = keycode_b
242 | c = keycode_c
243 | d = keycode_d
244 | e = keycode_e
245 | f = keycode_f
246 | g = keycode_g
247 | h = keycode_h
248 | i = keycode_i
249 | j = keycode_j
250 | k = keycode_k
251 | l = keycode_l
252 | m = keycode_m
253 | n = keycode_n
254 | o = keycode_o
255 | p = keycode_p
256 | q = keycode_q
257 | r = keycode_r
258 | s = keycode_s
259 | t = keycode_t
260 | u = keycode_u
261 | v = keycode_v
262 | w = keycode_w
263 | x = keycode_x
264 | y = keycode_y
265 | z = keycode_z
266 | _0 = keycode_0
267 | _1 = keycode_1
268 | _2 = keycode_2
269 | _3 = keycode_3
270 | _4 = keycode_4
271 | _5 = keycode_5
272 | _6 = keycode_6
273 | _7 = keycode_7
274 | _8 = keycode_8
275 | _9 = keycode_9
276 | space = keycode_space
277 | semicolon = keycode_semicolon
278 | comma = keycode_comma
279 | period = keycode_period
280 | slash = keycode_slash
281 | backtick = keycode_backtick
282 | left_bracket = keycode_left_bracket
283 | right_bracket = keycode_right_bracket
284 | backslash = keycode_backslash
285 | quote = keycode_quote
286 | hyphen = keycode_hyphen
287 | equals = keycode_equals
288 | return = keycode_return
289 | enter = keycode_return
290 | backspace = keycode_backspace
291 | tab = keycode_tab
292 | left_shift = keycode_left_shift
293 | right_shift = keycode_right_shift
294 | left_ctrl = keycode_left_ctrl
295 | right_ctrl = keycode_right_ctrl
296 | left_alt = keycode_left_alt
297 | right_alt = keycode_right_alt
298 | escape = keycode_escape
299 | f1 = keycode_f1
300 | f2 = keycode_f2
301 | f3 = keycode_f3
302 | f4 = keycode_f4
303 | f5 = keycode_f5
304 | f6 = keycode_f6
305 | f7 = keycode_f7
306 | f8 = keycode_f8
307 | f9 = keycode_f9
308 | f10 = keycode_f10
309 | f11 = keycode_f11
310 | f12 = keycode_f12
311 | left_arrow = keycode_left_arrow
312 | right_arrow = keycode_right_arrow
313 | up_arrow = keycode_up_arrow
314 | down_arrow = keycode_down_arrow
315 | delete = keycode_delete
316 | }
317 | KeyCode is a key on a keyboard.
318 | 319 |enum KeyModifier #
325 | enum KeyModifier {
326 | shift
327 | ctrl
328 | alt
329 | }
330 | KeyModifier is a key which can be pressed in combination with another key.
331 | 332 |struct DragParams #
338 | struct DragParams {
339 | __global:
340 | duration time.Duration = time.millisecond * 750
341 | button Button = .left
342 | }
343 | DragParams are the options for determining how the mouse is dragged across the screen.
344 | 345 |struct Keyboard #
351 | struct Keyboard {}
352 | Keyboard acts as a namespace for keyboard related functions.
353 | 354 |struct KeyboardWriteParams #
360 | struct KeyboardWriteParams {
361 | __global:
362 | speed time.Duration = 50 * time.millisecond
363 | }
364 | KeyboardWriteParams is the parameters for determining how Keyboard.write behaves.
365 | 366 |struct Mouse #
372 | struct Mouse {}
373 | Mouse acts as a namespace for mouse related functions.
374 | 375 |struct Pos #
380 | struct Pos {
381 | __global:
382 | x int
383 | y int
384 | }
385 | Pos is the X and Y coordinates on a screen.
386 | 387 |struct Screen #
393 | struct Screen {}
394 | Screen acts as a namespace for screen related functions.
395 | 396 |struct Size #
401 | struct Size {
402 | __global:
403 | width int
404 | height int
405 | }
406 | Size is the width and height of a screen.
407 | 408 |- README 414 |
- fn KeyCode.from_byte
-
415 |
417 | - fn Keyboard.press
-
418 |
420 | - fn Keyboard.write
-
421 |
423 | - fn Mouse.click
-
424 |
426 | - fn Mouse.double_click
-
427 |
429 | - fn Mouse.drag_rel
-
430 |
432 | - fn Mouse.drag_to
-
433 |
435 | - fn Mouse.get_pos
-
436 |
438 | - fn Mouse.get_pos_opt
-
439 |
441 | - fn Mouse.set_pos
-
442 |
444 | - fn Screen.compositor
-
445 |
447 | - fn Screen.refresh_rate
-
448 |
450 | - fn Screen.size
-
451 |
453 | - enum Button
-
454 |
456 | - enum Compositor
-
457 |
459 | - enum KeyCode
-
460 |
462 | - enum KeyModifier
-
463 |
465 | - struct DragParams
-
466 |
468 | - struct Keyboard
-
469 |
471 | - struct KeyboardWriteParams
-
472 |
474 | - struct Mouse
-
475 |
477 | - struct Pos
-
478 |
480 | - struct Screen
-
481 |
483 | - struct Size
-
484 |
486 |