Skip to content

Commit 49bfa6d

Browse files
committed
(#87) Keyboard API docs
1 parent ddeab54 commit 49bfa6d

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Diff for: lib/keyboard.class.ts

+39
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,33 @@ const inputIsString = (input: string[] | Key[]): input is string[] => {
88
return input.every((elem: string | Key) => typeof elem === "string");
99
};
1010

11+
/**
12+
* {@link Keyboard} class provides methods to emulate keyboard input
13+
*/
1114
export class Keyboard {
1215

16+
/**
17+
* Config object for {@link Keyboard} class
18+
*/
1319
public config = {
20+
/**
21+
* Configures the delay between single key events
22+
*/
1423
autoDelayMs: 300,
1524
};
1625

26+
/**
27+
* {@link Keyboard} class constructor
28+
* @param nativeAdapter {@link NativeAdapter} instance which bundles access to mouse, keyboard and clipboard
29+
*/
1730
constructor(private nativeAdapter: NativeAdapter) {
1831
this.nativeAdapter.setKeyboardDelay(this.config.autoDelayMs);
1932
}
2033

34+
/**
35+
* {@link type} types a sequence of {@link String} or single {@link Key}s via system keyboard
36+
* @param input Sequence of {@link String} or {@link Key} to type
37+
*/
2138
public type(...input: StringOrKey): Promise<Keyboard> {
2239
return new Promise<Keyboard>(async (resolve, reject) => {
2340
try {
@@ -36,6 +53,17 @@ export class Keyboard {
3653
});
3754
}
3855

56+
/**
57+
* {@link pressKey} presses and holds a single {@link Key} for {@link Key} combinations
58+
* Modifier {@link Key}s are to be given in "natural" ordering, so first modifier {@link Key}s, followed by the {@link Key} to press
59+
* @example
60+
* ```typescript
61+
* // Will press and hold key combination STRG + V
62+
* await keyboard.pressKey(Key.STRG, Key.A);
63+
* ```
64+
*
65+
* @param keys Array of {@link Key}s to press and hold
66+
*/
3967
public pressKey(...keys: Key[]): Promise<Keyboard> {
4068
return new Promise<Keyboard>(async (resolve, reject) => {
4169
try {
@@ -47,6 +75,17 @@ export class Keyboard {
4775
});
4876
}
4977

78+
/**
79+
* {@link pressKey} releases a single {@link Key} for {@link Key} combinations
80+
* Modifier {@link Key}s are to be given in "natural" ordering, so first modifier {@link Key}s, followed by the {@link Key} to press
81+
* @example
82+
* ```typescript
83+
* // Will release key combination STRG + V
84+
* await keyboard.releaseKey(Key.STRG, Key.A);
85+
* ```
86+
*
87+
* @param keys Array of {@link Key}s to release
88+
*/
5089
public releaseKey(...keys: Key[]): Promise<Keyboard> {
5190
return new Promise<Keyboard>(async (resolve, reject) => {
5291
try {

0 commit comments

Comments
 (0)