Automating the Mouse with AutoIt

How to automate the mouse with AutoIt, among other things useful to create bots.

AutoIt Logo

Automating the Mouse in AutoIt is primely done with the build-in functions. The below is a list of functions used to control the Mouse:

  1. MouseClick
  2. MouseClickDrag
  3. MouseDown
  4. MouseUp
  5. MouseGetPos
  6. MouseMove

Most of these function are pretty much self-explanatory, but we'll explain how to use them here anyway, additional information may be available in the reference for these Functions.

Automating Mouse Clicks

The below code will use the primary mouse button (usually the left button, unless the user has changed it), to click a given location on the screen once.

$x = 200
$y = 150
MouseClick("primary", $x, $y, 1)

This would click one time 200 pixels from the left side of the screen, and 150 pixels from the top of the screen.

Sometimes it may be useful to change the default coordinates, so that they are relative to the active window instead of the screen. This is done with the MouseCoordMode Option.

Click and Drag

To click and drag, use the MouseClickDrag function. This will be easier then pressing down and releasing buttons trough a combination of MouseDown and MouseUp actions.

MouseClickDrag("left", 0, 0, 250, 250)

Automating Mouse Movement

This is usually not necessary, as other functions automatically moves the mouse to the given location. If you want to click and drag, either to drag and drop, or make a selection, you can use MouseClickDrag instead.

MouseMove(10, 200) ; Left and Top in Pixels (X and Y)