Skip to content

Commit 7121302

Browse files
committed
New mouse example!
1 parent 89f412c commit 7121302

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

README.md

+15-9
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,27 @@ I [plan on](https://github.com/octalmage/robotjs/issues/64) using node-pre-gyp t
5151

5252
##### Mouse
5353

54-
```JavaScript
55-
//Get the mouse position, move it, then click.
54+
![](https://cloudup.com/cw5JY2cusx3+)
5655

56+
```JavaScript
57+
//Move the mouse across the screen as a sine wave.
5758
var robot = require("robotjs");
5859

59-
//Get the mouse position, returns an object with x and y.
60-
var mouse = robot.getMousePos();
61-
console.log("Mouse is at x:" + mouse.x + " y:" + mouse.y);
60+
//Speed up the mouse.
61+
robot.setMouseDelay(2);
6262

63-
//Move the mouse down by 100 pixels.
64-
robot.moveMouse(mouse.x, mouse.y + 100);
63+
var twoPI = Math.PI * 2.0;
64+
var screenSize = robot.getScreenSize();
65+
var height = (screenSize.height / 2) - 10;
66+
var width = screenSize.width;
6567

66-
//Left click!
67-
robot.mouseClick();
68+
for (var x = 0; x < width; x++)
69+
{
70+
y = height * Math.sin((twoPI * x) / width) + height;
71+
robot.moveMouse(x, y);
72+
}
6873
```
74+
6975
##### Keyboard
7076

7177
```JavaScript

0 commit comments

Comments
 (0)