Automating the Mouse with AutoIt

Automating mouse movement, and clicks with AutoIt.

4725 views
d

By. Jacob

Edited: 2019-09-11 16:19

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)

Tell us what you think:

  1. How to declare and work with variables in AutoIt, as well as some background information.
  2. Everything you need to know about working with minimized windows.
  3. How to set the request headers when performing HTTP requests.
  4. This Tutorial will focus on post requests in AutoIt, using the Winhttprequest.5.1 object.
  5. How to use while, for, and do until loops, and how to loop through arrays and object in AutoIt.

More in: AutoIt Tutorials