forked from octalmage/robotjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmouse.js
125 lines (99 loc) · 3.21 KB
/
mouse.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
var robot = require('..');
var lastKnownPos, currentPos;
//Increase delay to help it reliability.
robot.setMouseDelay(100);
describe('Mouse', () => {
it('Get the initial mouse position.', function()
{
expect(lastKnownPos = robot.getMousePos()).toBeTruthy();
expect(lastKnownPos.x !== undefined).toBeTruthy();
expect(lastKnownPos.y !== undefined).toBeTruthy();
});
it('Move the mouse.', function()
{
lastKnownPos = robot.moveMouse(0, 0);
expect(robot.moveMouse(100, 100) === 1).toBeTruthy();
currentPos = robot.getMousePos();
expect(currentPos.x === 100).toBeTruthy();
expect(currentPos.y === 100).toBeTruthy();
expect(function()
{
robot.moveMouse(0, 1, 2, 3);
}).toThrowError(/Invalid number/);
expect(function()
{
robot.moveMouse(0);
}).toThrowError(/Invalid number/);
expect(robot.moveMouse("0", "0") === 1).toBeTruthy();
});
it('Move the mouse smoothly.', function()
{
lastKnownPos = robot.moveMouseSmooth(0, 0);
expect(robot.moveMouseSmooth(100, 100) === 1).toBeTruthy();
currentPos = robot.getMousePos();
expect(currentPos.x).toEqual(100);
expect(currentPos.y).toEqual(100);
expect(function()
{
robot.moveMouseSmooth(0, 1, 2, 3);
}).toThrowError(/Invalid number/);
expect(function()
{
robot.moveMouseSmooth(0);
}).toThrowError(/Invalid number/);
expect(robot.moveMouseSmooth("0", "0") === 1).toBeTruthy();
});
it('Click the mouse.', function()
{
expect(robot.mouseClick()).toBeTruthy();
expect(robot.mouseClick("left") === 1).toBeTruthy();
expect(robot.mouseClick("middle") === 1).toBeTruthy();
expect(robot.mouseClick("right") === 1).toBeTruthy();
expect(robot.mouseClick("left", 1)).toBeTruthy();
expect(function()
{
robot.mouseClick("party");
}).toThrowError(/Invalid mouse/);
expect(function()
{
robot.mouseClick("0");
}).toThrowError(/Invalid mouse/);
expect(function()
{
robot.mouseClick("left", 0, "it");
}).toThrowError(/Invalid number/);
});
it('Drag the mouse.', function()
{
expect(robot.dragMouse(5, 5) === 1).toBeTruthy();
expect(function()
{
robot.dragMouse(0);
}).toThrowError(/Invalid number/);
expect(function()
{
robot.dragMouse(1, 1, "left", 5);
}).toThrowError(/Invalid number/);
expect(function()
{
robot.dragMouse(2, 2, "party");
}).toThrowError(/Invalid mouse/);
});
it('Mouse scroll.', function()
{
expect(lastKnownPos = robot.getMousePos()).toBeTruthy();
expect(robot.mouseClick() === 1).toBeTruthy();
expect(robot.scrollMouse(0, 1 * 120) === 1).toBeTruthy();
expect(robot.scrollMouse(0, 20 * 120) === 1).toBeTruthy();
expect(robot.scrollMouse(0, -5 * 120) === 1).toBeTruthy();
expect(robot.scrollMouse(1 * 120, 0) === 1).toBeTruthy();
expect(robot.scrollMouse(20 * 120, 0) === 1).toBeTruthy();
expect(robot.scrollMouse(-5 * 120, 0) === 1).toBeTruthy();
expect(robot.scrollMouse(-5 * 120, -5 * 120) === 1).toBeTruthy();
});
it('Mouse Toggle', function()
{
expect(lastKnownPos = robot.getMousePos()).toBeTruthy();
expect(robot.mouseToggle('up', 'right') === 1).toBeTruthy();
});
});