Cursor moving


To simulate the movement of the mouse, there are two main methods: mouse.move (dx, dy) and mouse.moveTo(x,y).
The method move moves the cursor relative to the current cursor position. Run the following code and note the starting position of the cursor and in which direction th cursor is moving. Parameters can be either positive or negative. If the parameter is negative, this indicates a backward shift along the coordinate axis and the cursor will move in the opposite direction.

for(i=0;i<100;i++){
    mouse.move(2,2);
}

The method moveTo moves the cursor to the specified point on the screen, where point 0,0 is the upper left corner of the screen. The coordinates can not be larger than the size of your monitor or less than zero.

for(i=0;i<100;i++){
    mouse.moveTo(i,i);
}

There are also many combined methods that simplify the work with the mouse. All of them conform to certain naming rules. If the ending At is added at the end, this means that the event will be performed at the specified point, the cursor will be moved to the specified point and then the event will be generated. If the method starts with the words moveAnd, it means that the cursor will first be moved relative to the previous position and then the event will be generated.


These methods do not add new functionality, but only simplify the writing and reading of the code. For example, the following is an example of code that performs exactly the same functions.


mouse.moveTo(0,0);// move the cursor to the point 0,0 
mouse.press('LEFT');// press the left mouse button
mouse.release('LEFT');// release the left mouse button

// similarly
mouse.moveTo(0,0);
mouse.click('LEFT');

// similarly
mouse.clickAt('LEFT',0,0);


mouse.move(10,10);// move the cursor two pixels to the right and down
mouse.press('LEFT');// press the left mouse button
mouse.release('LEFT');// release the left mouse button

// similarly
mouse.move(10,10);
mouse.click('LEFT');
        
// similarly
mouse.moveAndClick('LEFT',10,10);