@@ -4,16 +4,37 @@ import { linear } from "./movementtype.function";
4
4
import { Point } from "./point.class" ;
5
5
import { sleep } from "./sleep.function" ;
6
6
7
+ /**
8
+ * {@link Mouse } class provides methods to emulate mouse input
9
+ */
7
10
export class Mouse {
11
+ /**
12
+ * Config object for {@link Mouse} class
13
+ */
8
14
public config = {
15
+ /**
16
+ * Configures the delay between single mouse events
17
+ */
9
18
autoDelayMs : 100 ,
19
+
20
+ /**
21
+ * Configures the speed in pixels/second for mouse movement
22
+ */
10
23
mouseSpeed : 1000 ,
11
24
} ;
12
25
26
+ /**
27
+ * {@link Mouse } class constructor
28
+ * @param native {@link NativeAdapter } instance which bundles access to mouse, keyboard and clipboard
29
+ */
13
30
constructor ( private native : NativeAdapter ) {
14
31
this . native . setMouseDelay ( 0 ) ;
15
32
}
16
33
34
+ /**
35
+ * {@link setPosition } instantly moves the mouse cursor to a given {@link Point }
36
+ * @param target {@link Point } to move the cursor to
37
+ */
17
38
public async setPosition ( target : Point ) : Promise < Mouse > {
18
39
return new Promise < Mouse > ( async ( resolve , reject ) => {
19
40
try {
@@ -25,10 +46,18 @@ export class Mouse {
25
46
} ) ;
26
47
}
27
48
49
+ /**
50
+ * {@link getPosition } returns a {@link Point } representing the current mouse position
51
+ */
28
52
public getPosition ( ) : Promise < Point > {
29
53
return this . native . currentMousePosition ( ) ;
30
54
}
31
55
56
+ /**
57
+ * {@link move } moves the mouse cursor along a given path of {@link Point }s, according to a movement type
58
+ * @param path Array of {@link Point}s to follow
59
+ * @param movementType Defines the type of mouse movement. Would allow to configured acceleration etc. (Default: {@link linear}, no acceleration)
60
+ */
32
61
public async move ( path : Point [ ] | Promise < Point [ ] > , movementType = linear ) : Promise < Mouse > {
33
62
return new Promise < Mouse > ( async ( resolve , reject ) => {
34
63
try {
@@ -47,6 +76,9 @@ export class Mouse {
47
76
} ) ;
48
77
}
49
78
79
+ /**
80
+ * {@link leftClick } performs a click with the left mouse button
81
+ */
50
82
public async leftClick ( ) : Promise < Mouse > {
51
83
return new Promise < Mouse > ( async resolve => {
52
84
await sleep ( this . config . autoDelayMs ) ;
@@ -55,6 +87,9 @@ export class Mouse {
55
87
} ) ;
56
88
}
57
89
90
+ /**
91
+ * {@link rightClick } performs a click with the right mouse button
92
+ */
58
93
public async rightClick ( ) : Promise < Mouse > {
59
94
return new Promise < Mouse > ( async ( resolve , reject ) => {
60
95
try {
@@ -67,6 +102,11 @@ export class Mouse {
67
102
} ) ;
68
103
}
69
104
105
+ /**
106
+ * {@link scrollDown } scrolls down for a given amount of "steps"
107
+ * Please note that the actual scroll distance of a single "step" is OS dependent
108
+ * @param amount The amount of "steps" to scroll
109
+ */
70
110
public async scrollDown ( amount : number ) : Promise < Mouse > {
71
111
return new Promise < Mouse > ( async ( resolve , reject ) => {
72
112
try {
@@ -79,6 +119,11 @@ export class Mouse {
79
119
} ) ;
80
120
}
81
121
122
+ /**
123
+ * {@link scrollUp } scrolls up for a given amount of "steps"
124
+ * Please note that the actual scroll distance of a single "step" is OS dependent
125
+ * @param amount The amount of "steps" to scroll
126
+ */
82
127
public async scrollUp ( amount : number ) : Promise < Mouse > {
83
128
return new Promise < Mouse > ( async ( resolve , reject ) => {
84
129
try {
@@ -91,6 +136,11 @@ export class Mouse {
91
136
} ) ;
92
137
}
93
138
139
+ /**
140
+ * {@link scrollLeft } scrolls left for a given amount of "steps"
141
+ * Please note that the actual scroll distance of a single "step" is OS dependent
142
+ * @param amount The amount of "steps" to scroll
143
+ */
94
144
public async scrollLeft ( amount : number ) : Promise < Mouse > {
95
145
return new Promise < Mouse > ( async ( resolve , reject ) => {
96
146
try {
@@ -103,6 +153,11 @@ export class Mouse {
103
153
} ) ;
104
154
}
105
155
156
+ /**
157
+ * {@link scrollRight } scrolls right for a given amount of "steps"
158
+ * Please note that the actual scroll distance of a single "step" is OS dependent
159
+ * @param amount The amount of "steps" to scroll
160
+ */
106
161
public async scrollRight ( amount : number ) : Promise < Mouse > {
107
162
return new Promise < Mouse > ( async ( resolve , reject ) => {
108
163
try {
@@ -115,6 +170,11 @@ export class Mouse {
115
170
} ) ;
116
171
}
117
172
173
+ /**
174
+ * {@link drag } drags the mouse along a certain path
175
+ * In summary, {@link drag} presses and holds the left mouse button, moves the mouse and releases the left button
176
+ * @param path The path of {@link Point}s to drag along
177
+ */
118
178
public async drag ( path : Point [ ] | Promise < Point [ ] > ) : Promise < Mouse > {
119
179
return new Promise < Mouse > ( async ( resolve , reject ) => {
120
180
try {
@@ -129,6 +189,10 @@ export class Mouse {
129
189
} ) ;
130
190
}
131
191
192
+ /**
193
+ * {@link pressButton } presses and holds a mouse button
194
+ * @param btn The {@link Button} to press and hold
195
+ */
132
196
public async pressButton ( btn : Button ) : Promise < Mouse > {
133
197
return new Promise < Mouse > ( async ( resolve , reject ) => {
134
198
try {
@@ -140,6 +204,10 @@ export class Mouse {
140
204
} ) ;
141
205
}
142
206
207
+ /**
208
+ * {@link releaseButton } releases a mouse button previously pressed via {@link pressButton }
209
+ * @param btn The {@link Button} to release
210
+ */
143
211
public async releaseButton ( btn : Button ) : Promise < Mouse > {
144
212
return new Promise < Mouse > ( async ( resolve , reject ) => {
145
213
try {
0 commit comments