Skip to content

Commit cc7ee90

Browse files
committed
(#87) Mouse API docs
1 parent 42a7c5f commit cc7ee90

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

lib/mouse.class.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,37 @@ import { linear } from "./movementtype.function";
44
import { Point } from "./point.class";
55
import { sleep } from "./sleep.function";
66

7+
/**
8+
* {@link Mouse} class provides methods to emulate mouse input
9+
*/
710
export class Mouse {
11+
/**
12+
* Config object for {@link Mouse} class
13+
*/
814
public config = {
15+
/**
16+
* Configures the delay between single mouse events
17+
*/
918
autoDelayMs: 100,
19+
20+
/**
21+
* Configures the speed in pixels/second for mouse movement
22+
*/
1023
mouseSpeed: 1000,
1124
};
1225

26+
/**
27+
* {@link Mouse} class constructor
28+
* @param native {@link NativeAdapter} instance which bundles access to mouse, keyboard and clipboard
29+
*/
1330
constructor(private native: NativeAdapter) {
1431
this.native.setMouseDelay(0);
1532
}
1633

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+
*/
1738
public async setPosition(target: Point): Promise<Mouse> {
1839
return new Promise<Mouse>(async (resolve, reject) => {
1940
try {
@@ -25,10 +46,18 @@ export class Mouse {
2546
});
2647
}
2748

49+
/**
50+
* {@link getPosition} returns a {@link Point} representing the current mouse position
51+
*/
2852
public getPosition(): Promise<Point> {
2953
return this.native.currentMousePosition();
3054
}
3155

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+
*/
3261
public async move(path: Point[] | Promise<Point[]>, movementType = linear): Promise<Mouse> {
3362
return new Promise<Mouse>(async (resolve, reject) => {
3463
try {
@@ -47,6 +76,9 @@ export class Mouse {
4776
});
4877
}
4978

79+
/**
80+
* {@link leftClick} performs a click with the left mouse button
81+
*/
5082
public async leftClick(): Promise<Mouse> {
5183
return new Promise<Mouse>(async resolve => {
5284
await sleep(this.config.autoDelayMs);
@@ -55,6 +87,9 @@ export class Mouse {
5587
});
5688
}
5789

90+
/**
91+
* {@link rightClick} performs a click with the right mouse button
92+
*/
5893
public async rightClick(): Promise<Mouse> {
5994
return new Promise<Mouse>(async (resolve, reject) => {
6095
try {
@@ -67,6 +102,11 @@ export class Mouse {
67102
});
68103
}
69104

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+
*/
70110
public async scrollDown(amount: number): Promise<Mouse> {
71111
return new Promise<Mouse>(async (resolve, reject) => {
72112
try {
@@ -79,6 +119,11 @@ export class Mouse {
79119
});
80120
}
81121

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+
*/
82127
public async scrollUp(amount: number): Promise<Mouse> {
83128
return new Promise<Mouse>(async (resolve, reject) => {
84129
try {
@@ -91,6 +136,11 @@ export class Mouse {
91136
});
92137
}
93138

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+
*/
94144
public async scrollLeft(amount: number): Promise<Mouse> {
95145
return new Promise<Mouse>(async (resolve, reject) => {
96146
try {
@@ -103,6 +153,11 @@ export class Mouse {
103153
});
104154
}
105155

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+
*/
106161
public async scrollRight(amount: number): Promise<Mouse> {
107162
return new Promise<Mouse>(async (resolve, reject) => {
108163
try {
@@ -115,6 +170,11 @@ export class Mouse {
115170
});
116171
}
117172

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+
*/
118178
public async drag(path: Point[] | Promise<Point[]>): Promise<Mouse> {
119179
return new Promise<Mouse>(async (resolve, reject) => {
120180
try {
@@ -129,6 +189,10 @@ export class Mouse {
129189
});
130190
}
131191

192+
/**
193+
* {@link pressButton} presses and holds a mouse button
194+
* @param btn The {@link Button} to press and hold
195+
*/
132196
public async pressButton(btn: Button): Promise<Mouse> {
133197
return new Promise<Mouse>(async (resolve, reject) => {
134198
try {
@@ -140,6 +204,10 @@ export class Mouse {
140204
});
141205
}
142206

207+
/**
208+
* {@link releaseButton} releases a mouse button previously pressed via {@link pressButton}
209+
* @param btn The {@link Button} to release
210+
*/
143211
public async releaseButton(btn: Button): Promise<Mouse> {
144212
return new Promise<Mouse>(async (resolve, reject) => {
145213
try {

0 commit comments

Comments
 (0)