forked from zz85/robotjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmouse.js
113 lines (87 loc) · 2.91 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
var test = require('tape');
var robot = require('..');
var lastKnownPos, currentPos;
//Increase delay to help test reliability.
robot.setMouseDelay(100);
test('Get the initial mouse position.', function(t)
{
t.plan(3);
t.ok(lastKnownPos = robot.getMousePos(), 'successfully retrieved mouse position.');
t.ok(lastKnownPos.x !== undefined, 'mousepos.x is a valid value.');
t.ok(lastKnownPos.y !== undefined, 'mousepos.y is a valid value.');
});
test('Move the mouse.', function(t)
{
t.plan(6);
lastKnownPos = robot.moveMouse(0, 0);
t.ok(robot.moveMouse(100, 100) === 1, 'successfully moved the mouse.');
currentPos = robot.getMousePos();
t.ok(currentPos.x === 100, 'mousepos.x is correct.');
t.ok(currentPos.y === 100, 'mousepos.y is correct.');
t.throws(function()
{
robot.moveMouse(0, 1, 2, 3);
}, /Invalid number/, 'move mouse to (0, 1, 2, 3).');
t.throws(function()
{
robot.moveMouse(0);
}, /Invalid number/, 'move mouse to (0).');
t.ok(robot.moveMouse("0", "0") === 1, 'move mouse to ("0", "0").');
});
test('Move the mouse smoothly.', function(t)
{
t.plan(6);
lastKnownPos = robot.moveMouseSmooth(0, 0);
t.ok(robot.moveMouseSmooth(100, 100) === 1, 'successfully moved the mouse.');
currentPos = robot.getMousePos();
t.ok(currentPos.x === 100, 'mousepos.x is correct.');
t.ok(currentPos.y === 100, 'mousepos.y is correct.');
t.throws(function()
{
robot.moveMouseSmooth(0, 1, 2, 3);
}, /Invalid number/, 'move mouse to (0, 1, 2, 3).');
t.throws(function()
{
robot.moveMouseSmooth(0);
}, /Invalid number/, 'move mouse to (0).');
t.ok(robot.moveMouseSmooth("0", "0") === 1, 'move mouse to ("0", "0").');
});
test('Click the mouse.', function(t)
{
t.plan(8);
t.ok(robot.mouseClick(), 'click the mouse (no button specified).');
t.ok(robot.mouseClick("left") === 1, 'click the left mouse button.');
t.ok(robot.mouseClick("middle") === 1, 'click the middle mouse button.');
t.ok(robot.mouseClick("right") === 1, 'click the right mouse button.');
t.ok(robot.mouseClick("left", 1), 'double click the left mouse button.');
t.throws(function()
{
robot.mouseClick("party");
}, /Invalid mouse/, 'click an incorrect mouse button (party).');
t.throws(function()
{
robot.mouseClick("0");
}, /Invalid mouse/, 'click an incorrect mouse button (0).');
t.throws(function()
{
robot.mouseClick("left", 0, "test");
}, /Invalid number/, 'click the mouse with an extra argument.');
});
test('Drag the mouse.', function(t)
{
t.plan(4);
t.ok(robot.dragMouse(5, 5) === 1, 'successfully dragged the mouse.');
t.throws(function()
{
robot.dragMouse(0);
}, /Invalid number/, 'drag mouse to (0).');
t.throws(function()
{
robot.dragMouse(1, 1, "left", 5);
}, /Invalid number/, 'drag mouse with extra argument.');
t.throws(function()
{
robot.dragMouse(2, 2, "party");
}, /Invalid mouse/, 'drag an incorrect mouse button (party).');
});
//TODO: Need tests for mouseToggle, and scrollMouse.