Skip to content

Commit

Permalink
(#409) Only sleep on keyboard inputs if autoDelay > 0
Browse files Browse the repository at this point in the history
  • Loading branch information
s1hofmann committed Sep 30, 2022
1 parent c5fb450 commit 65f5770
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/keyboard.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ export class KeyboardClass {
try {
if (inputIsString(input)) {
for (const char of input.join(" ").split("")) {
await sleep(this.config.autoDelayMs);
await this.providerRegistry.getKeyboard().type(char);
if (this.config.autoDelayMs > 0) {
await sleep(this.config.autoDelayMs);
}
await this.providerRegistry.getKeyboard().type(char);
}
} else {
await this.providerRegistry.getKeyboard().click(...input as Key[]);
Expand All @@ -73,7 +75,9 @@ export class KeyboardClass {
public pressKey(...keys: Key[]): Promise<KeyboardClass> {
return new Promise<KeyboardClass>(async (resolve, reject) => {
try {
await sleep(this.config.autoDelayMs);
if (this.config.autoDelayMs > 0) {
await sleep(this.config.autoDelayMs);
}
await this.providerRegistry.getKeyboard().pressKey(...keys);
resolve(this);
} catch (e) {
Expand All @@ -96,7 +100,9 @@ export class KeyboardClass {
public releaseKey(...keys: Key[]): Promise<KeyboardClass> {
return new Promise<KeyboardClass>(async (resolve, reject) => {
try {
await sleep(this.config.autoDelayMs);
if (this.config.autoDelayMs > 0) {
await sleep(this.config.autoDelayMs);
}
await this.providerRegistry.getKeyboard().releaseKey(...keys);
resolve(this);
} catch (e) {
Expand Down

0 comments on commit 65f5770

Please sign in to comment.