src/xdo

    Dark Mode
Search:
Group by:

Nim-Xdo

  • Nim GUI Automation Linux, simulate user interaction, mouse and keyboard control from Nim code, procs for common actions.

Example:

import src/xdo
## XDo works on Linux OS.
when defined(linux):
  ## Basic example of mouse and keyboard control from code.
  import strutils
  echo get_id()
  echo get_pid()
  echo move_mouse(x = "+99", y = "+99")
  echo move_mouse_left_100px(2)
  echo move_mouse_top_100px(2)
  echo mouse_move_alternating(x = 9, y = 5, 3)
  # echo key_0()
  # echo key_1()
  # echo key_2()
  # echo key_3()
  # echo key_4()
  # echo key_5()
  # echo key_6()
  # echo key_7()
  # echo key_8()
  # echo key_9()
  # echo hide_all_but_focused_window()
  # echo hide_focused_window()

Types

XDoActions = enum
  closeFocusedWindow = "xdo close -c;", hideFocusedWindow = "xdo hide -c;",
  showFocusedWindow = "xdo show -c;", raiseFocusedWindow = "xdo raise -c;",
  lowerFocusedWindow = "xdo lower -c;",
  hideAllButFocusedWindow = "xdo hide -dr;",
  closeAllButFocusedWindow = "xdo close -dr;",
  raiseAllButFocusedWindow = "xdo raise -dr;",
  lowerAllButFocusedWindow = "xdo lower -dr;",
  showAllButFocusedWindow = "xdo show -dr;",
  moveMouseTopLeft = "xdo pointer_motion -x 0 -y 0;",
  mouseLeftClick = "xdo button_press -k 1;xdo button_release -k 1;",
  mouseMiddleClick = "xdo button_press -k 2;xdo button_release -k 2;",
  mouseRightClick = "xdo button_press -k 3;xdo button_release -k 3;", mouseDoubleLeftClick = "xdo button_press -k 1;xdo button_release -k 1;xdo button_press -k 1;xdo button_release -k 1;", mouseDoubleMiddleClick = "xdo button_press -k 2;xdo button_release -k 2;xdo button_press -k 2;xdo button_release -k 2;", mouseDoubleRightClick = "xdo button_press -k 3;xdo button_release -k 3;xdo button_press -k 3;xdo button_release -k 3;", mouseTripleLeftClick = "xdo button_press -k 1;xdo button_release -k 1;xdo button_press -k 1;xdo button_release -k 1;xdo button_press -k 1;xdo button_release -k 1;", mouseTripleMiddleClick = "xdo button_press -k 2;xdo button_release -k 2;xdo button_press -k 2;xdo button_release -k 2;xdo button_press -k 2;xdo button_release -k 2;", mouseTripleRightClick = "xdo button_press -k 3;xdo button_release -k 3;xdo button_press -k 3;xdo button_release -k 3;xdo button_press -k 3;xdo button_release -k 3;",
  keyBackspace = "xdo key_press -k 8;xdo key_release -k 8;",
  keyTab = "xdo key_press -k 9;xdo key_release -k 9;",
  keyEnter = "xdo key_press -k 13;xdo key_release -k 13;",
  keyShift = "xdo key_press -k 16;xdo key_release -k 16;",
  keyCtrl = "xdo key_press -k 17;xdo key_release -k 17;", keyCtrlEnter = "xdo key_press -k 17;xdo key_press -k 36;xdo key_release -k 17;xdo key_release -k 36;",
  keyAlt = "xdo key_press -k 18;xdo key_release -k 18;",
  keyPause = "xdo key_press -k 19;xdo key_release -k 19;",
  keyCapslock = "xdo key_press -k 20;xdo key_release -k 20;",
  keyEsc = "xdo key_press -k 27;xdo key_release -k 27;",
  keySpace = "xdo key_press -k 32;xdo key_release -k 32;",
  keyPageup = "xdo key_press -k 33;xdo key_release -k 33;",
  keyPagedown = "xdo key_press -k 34;xdo key_release -k 34;",
  keyEnd = "xdo key_press -k 35;xdo key_release -k 35;",
  keyHome = "xdo key_press -k 36;xdo key_release -k 36;",
  keyArrowLeft = "xdo key_press -k 37;xdo key_release -k 37;",
  keyArrowUp = "xdo key_press -k 38;xdo key_release -k 38;",
  keyArrowRight = "xdo key_press -k 39;xdo key_release -k 39;",
  keyArrowDown = "xdo key_press -k 40;xdo key_release -k 40;",
  keyInsert = "xdo key_press -k 45;xdo key_release -k 45;",
  keyDelete = "xdo key_press -k 46;xdo key_release -k 46;",
  keyNumlock = "xdo key_press -k 144;xdo key_release -k 144;",
  keyScrolllock = "xdo key_press -k 145;xdo key_release -k 145;",
  keyMycomputer = "xdo key_press -k 182;xdo key_release -k 182;",
  keyMycalculator = "xdo key_press -k 183;xdo key_release -k 183;",
  keyWindows = "xdo key_press -k 91;xdo key_release -k 91;",
  keyRightclick = "xdo key_press -k 93;xdo key_release -k 93;",
  keyNumpad0 = "xdo key_press -k 96;xdo key_release -k 96;",
  keyNumpad1 = "xdo key_press -k 97;xdo key_release -k 97;",
  keyNumpad2 = "xdo key_press -k 98;xdo key_release -k 98;",
  keyNumpad3 = "xdo key_press -k 99;xdo key_release -k 99;",
  keyNumpad4 = "xdo key_press -k 100;xdo key_release -k 100;",
  keyNumpad5 = "xdo key_press -k 101;xdo key_release -k 101;",
  keyNumpad6 = "xdo key_press -k 102;xdo key_release -k 102;",
  keyNumpad7 = "xdo key_press -k 103;xdo key_release -k 103;",
  keyNumpad8 = "xdo key_press -k 104;xdo key_release -k 104;",
  keyNumpad9 = "xdo key_press -k 105;xdo key_release -k 105;",
  keyNumpadAsterisk = "xdo key_press -k 106;xdo key_release -k 106;",
  keyNumpadPlus = "xdo key_press -k 107;xdo key_release -k 107;",
  keyNumpadMinus = "xdo key_press -k 109;xdo key_release -k 109;",
  keyNumpadDot = "xdo key_press -k 110;xdo key_release -k 110;",
  keyNumpadSlash = "xdo key_press -k 111;xdo key_release -k 111;",
  keyF1 = "xdo key_press -k 112;xdo key_release -k 112;",
  keyF2 = "xdo key_press -k 113;xdo key_release -k 113;",
  keyF3 = "xdo key_press -k 114;xdo key_release -k 114;",
  keyF4 = "xdo key_press -k 115;xdo key_release -k 115;",
  keyF5 = "xdo key_press -k 116;xdo key_release -k 116;",
  keyF6 = "xdo key_press -k 117;xdo key_release -k 117;",
  keyF7 = "xdo key_press -k 118;xdo key_release -k 118;",
  keyF8 = "xdo key_press -k 119;xdo key_release -k 119;",
  keyF9 = "xdo key_press -k 120;xdo key_release -k 120;",
  keyF10 = "xdo key_press -k 121;xdo key_release -k 121;",
  keyF11 = "xdo key_press -k 122;xdo key_release -k 122;",
  keyF12 = "xdo key_press -k 123;xdo key_release -k 123;",
  key0 = "xdo key_press -k 48;xdo key_release -k 48;",
  key1 = "xdo key_press -k 49;xdo key_release -k 49;",
  key2 = "xdo key_press -k 50;xdo key_release -k 50;",
  key3 = "xdo key_press -k 51;xdo key_release -k 51;",
  key4 = "xdo key_press -k 52;xdo key_release -k 52;",
  key5 = "xdo key_press -k 53;xdo key_release -k 53;",
  key6 = "xdo key_press -k 54;xdo key_release -k 54;",
  key7 = "xdo key_press -k 55;xdo key_release -k 55;",
  key8 = "xdo key_press -k 56;xdo key_release -k 56;",
  key9 = "xdo key_press -k 57;xdo key_release -k 57;", clickCtrlADelete = "xdo button_press -k 1;xdo button_release -k 1;xdo key_press -k 17;xdo button_press -k 38;xdo button_release -k 38;xdo key_release -k 17;xdo key_press -k 8;xdo key_release -k 8;", ctrlShiftI = "xdo key_press -k 17;xdo key_press -k 16;xdo button_press -k 31;xdo button_release -k 31;xdo key_release -k 16;xdo key_release -k 17;", ctrlFDelete = "xdo key_press -k 17;xdo button_press -k 41;xdo button_release -k 41;xdo key_release -k 17;xdo key_press -k 8;xdo key_release -k 8;"

Procs

func toCmd(c: char): string {.noinline, ...raises: [], tags: [].}
func toCmd(actions: openArray[XDoActions]): string {....raises: [], tags: [].}
func toCmd(actions: openArray[char]): string {....raises: [], tags: [].}
proc mouse_move_alternating(x, y: string or int; repetitions = 1.Positive): string {.
    inline.}
Move mouse alternating to Left/Right Up/Down, AKA Zig-Zag movements.
proc key_numbers_click(repetitions = 1.Positive): string {.inline, ...raises: [],
    tags: [].}
This function types the keys like: 1,10clicks,2,10clicks,3,10clicks,etc up to 9 (in games, shoot weapons 1 to 9).

Templates

template getPid(): string
Get Process ID.
template getId(): string
Get Window ID.
template move_mouse(x, y: string or int): string
Move mouse to move position pixel coordinates (X, Y).
template move_window(x, y: string or int; pid: Positive): string
Move window to move position pixel coordinates (X, Y).
template resize_window(x, y: string or int; pid: Positive): string
Resize window up to move position pixel coordinates (X, Y).
template activate_this_window(pid: Positive): string
Force to Activate this window by PID.
template move_mouse_top_100px(repetitions: Positive): string
Move mouse to Top Y=0, then repeat move Bottom on jumps of 100px each.
template move_mouse_left_100px(repetitions: Positive): string
Move mouse to Left X=0, then repeat move Right on jumps of 100px each.
template mouse_spamm_left_click(repetitions = 1.Positive): string
Spamm Mouse Left Click as fast as possible.
template mouse_spamm_middle_click(repetitions = 1.Positive): string
Spamm Mouse Middle Click as fast as possible.
template mouse_spamm_right_click(repetitions = 1.Positive): string
Spamm Mouse Right Click as fast as possible.
template mouse_swipe_horizontal(x: string or int): string
Mouse Swipe to Left or Right, Hold Left Click+Drag Horizontally+Release Left Click.
template mouse_swipe_vertical(y: string or int): string
Mouse Swipe to Up or Down, Hold Left Click+Drag Vertically+Release Left Click.
template key_wasd(repetitions = 1.Positive): string
Keyboard Keys W,A,S,D as fast as possible (in games,make circles).
template key_spamm_space(repetitions = 1.Positive): string
Keyboard Key Space as fast as possible (in games,bunny hop).
template key_w_click(repetitions = 1.Positive): string
Keyboard Key W and Mouse Left Click as fast as possible (in games,forward+hit).
template key_w_space(repetitions = 1.Positive): string
Keyboard Keys W,Space as fast as possible (in games, forward+jump).
template key_w_space_click(repetitions = 1.Positive): string
Keyboard Keys W,Space and Mouse Left Click (in games, forward+jump+hit).
template key_w_e(repetitions = 1.Positive): string
Keyboard Keys W,E as fast as possible (in games, forward+use).