Menu Close

The most complete and easiest AutoHotkey mouse movement and control tutorial on Earth

The most basic way to create an authentic macro with AutoHotkey is mouse click. The fact is that the code is lengthened and inefficient, so if you do not mind, you can implement most macros with a click of the mouse (for example, you can do everything from desktop to new folder to run text file with a mouse click, 'Run'It's as simple as a single command.) It's a very alpha character in AutoHotkey macros.

There are quite a number of mouse-related AutoHotkey macros, and you can implement most of the mouse-related events if you know just three things: 'MouseMove, MouseClick, MouseGetPos' - you do not need 'Click, MouseClickDrag, LeftClick, RightClick' (Later we'll click on 'ControlClick' and disable the control without actually using the mouse.

지구에서-가장-완벽하고-쉬운-오토핫키-마우스-이동과-제어-튜토리얼-the-most-complete-and-easiest-autohotkey-mouse-movement-and-control-tutorial-on-earth

    How does 'MouseMove' work?

MouseMove, X, Y [, Speed, Relative]

Declare the command to move the mouse with 'MouseMove', and specify the coordinates of the mouse with 'X' (horizontal) and 'Y' (vertical) values entered. If you want to move the mouse to the position of '100px' to the right from the top left of the screen and '100px' to the bottom, code as follows.

MouseMove, 100, 100

The value in brackets is not necessarily small, but the code works and sets the speed at which the mouse moves with 'Speed'. '0' moves immediately, the higher the number, the slower it moves and '100' is the limit. If nothing is set, the default '2' is applied. If you want to move the mouse directly to the coordinates of 'x100', 'y100', code as follows.

MouseMove, 100, 100, 0

'Relative' changes relative commands to move to absolute position with existing 'X' and 'Y' values, ie

MouseMove, 100, 100

Moves the mouse to the 'x100' and 'y100' positions on the screen

MouseMove, 100, 100, , R

If you add 'Relative' or 'R', it will move 100 points from 'X' axis and '100' to 'Y' axis at the current pointer position. If you write a negative value, it moves in the opposite direction.

    How does 'MouseClick' work?

MouseClick [, WhichButton, X, Y, ClickCount, Speed, DownOrUp, Relative]

The basic operation is the same as 'MouseMove' but it does not only move but also input such as left click, right click, wheel button click, wheel button roll, x button (additional button to the left of gaming mouse etc.) .

The code in brackets works without any code, and the defaults when omitted are 'WhichButton = Left', 'X, Y = current position', 'ClickCount = 1', 'Speed = 2'.

Here's the code that once left-clicks at the current location:

MouseClick

Here's the code to right-click once on the current location. (You can enter special keys such as 'Left' for left click, 'Right' for right click, 'Middle' for wheel click, 'Wheelup', 'Wheeldown' wheel up and down, 'Xbutton1', 'xbutton2' And can be abbreviated as L, R, M, WU, WD, X1, and X2, respectively.

MouseClick, Right

Here is the code to click on the coordinates of 'x100', 'y100'.

MouseClick, Left, 100, 100

Here's the code that double-clicks on the coordinates 'x100', 'y100':

MouseClick, Left, 100, 100, 2

Here's the code that immediately moves the coordinates of 'x100' and 'y100' and double-clicks them.

MouseClick, Left, 100, 100, 2, 0

'x100', 'y100' Move to the coordinates and hold down the left click.

MouseClick, Left, 100, 100, , , D

Here's the code to move to the coordinates of 'x100', 'y100', left-click to drag, and left-click to 'x200', 'y200'

MouseClick, Left, 100, 100, , , D
MouseClick, Left, 200, 200, , , U

The code that moves relative to the current mouse pointer position by 'x100' and 'y100' instead of moving through the absolute value in the coordinates of 'x100' and 'y100' on the screen is as follows.

MouseClick, Left, 100, 100, , , , R

    Function and usage of 'MouseGetPos'

MouseGetPos [, OutputVarX, OutputVarY, OutputVarWin, OutputVarControl, Flag]

The functions related to 'MouseGetPos' are the same as above.

MouseGetPos, OutputVarX, OutputVarY

You only need to know the above functions. The code that stores the coordinates of the current mouse position in 'OuputVarX' and 'OutputVarY' values and actually returns the coordinates of 'x100' and 'y100' Respectively.

MouseGetPos, 1X, 1Y
MouseMove, 100, 100
MouseMove, %1X%, %1Y%

Next, this 'MouseGetPos' is the most commonly used purpose. If you want to move the mouse position to 'x100' or 'y100' in the saved position, you can code as follows.

MouseGetPos, 1X, 1Y
MouseMove, 1X+100, 1Y+100

At first glance, it may look like the 'Relative' function of the previous 'MouseMove', but since the '1X' and '1Y' values are stored while the corresponding AutoHotkey is running, Function.

    Practice example

Here is a real case code that uses all of the functions learned today to finish and actually clicks F1 button to save the current position and then click on the coordinates of 'x100', 'y100' and return again.

F1::
MouseGetPos, 1X, 1Y
MouseClick, Left, 100, 100
MouseClick, Left, %1X%, %1Y%
Return

If you only understand what is on this page, you can say that you have mastered the basic mouse events of AutoHotkey. So, even if you do not understand it at once, let's save it and then master it again when you need it. It is best to try pasting the examples yourself, or try coding with the content you actually learned.

Leave a Reply

Your email address will not be published.

Posted in AutoHotkey, All

이메일 구독 - Email Subs

최선을 다해 직접 만든 콘텐츠만 공유합니다.
We share the best content we have created.