From 5791dcf9c823ded63cf2757bde4955eff84b5d7e Mon Sep 17 00:00:00 2001 From: Simon Hofmann Date: Thu, 27 Oct 2022 00:11:44 +0200 Subject: [PATCH 1/2] (#445) Extracted config interfaces for keyboard, mouse and screen --- lib/keyboard.class.ts | 15 +++++++++---- lib/mouse.class.ts | 27 +++++++++++++--------- lib/screen.class.ts | 52 +++++++++++++++++++++++++------------------ 3 files changed, 57 insertions(+), 37 deletions(-) diff --git a/lib/keyboard.class.ts b/lib/keyboard.class.ts index a0245812..7a438644 100644 --- a/lib/keyboard.class.ts +++ b/lib/keyboard.class.ts @@ -8,6 +8,16 @@ const inputIsString = (input: (string | Key)[]): input is string[] => { return input.every((elem: string | Key) => typeof elem === "string"); }; +/** + * Config object for {@link KeyboardClass} class + */ +export interface KeyboardConfig { + /** + * Configures the delay between single key events + */ + autoDelayMs: number; +} + /** * {@link KeyboardClass} class provides methods to emulate keyboard input */ @@ -15,10 +25,7 @@ export class KeyboardClass { /** * Config object for {@link KeyboardClass} class */ - public config = { - /** - * Configures the delay between single key events - */ + public config: KeyboardConfig = { autoDelayMs: 300, }; diff --git a/lib/mouse.class.ts b/lib/mouse.class.ts index 9091e776..5f66613d 100644 --- a/lib/mouse.class.ts +++ b/lib/mouse.class.ts @@ -9,21 +9,26 @@ import { import { ProviderRegistry } from "./provider/provider-registry.class"; /** - * {@link MouseClass} class provides methods to emulate mouse input + * Config object for {@link MouseClass} class */ -export class MouseClass { +export interface MouseConfig { /** - * Config object for {@link MouseClass} class + * Configures the delay between single mouse events */ - public config = { - /** - * Configures the delay between single mouse events - */ - autoDelayMs: 100, + autoDelayMs: number; + + /** + * Configures the speed in pixels/second for mouse movement + */ + mouseSpeed: number; +} - /** - * Configures the speed in pixels/second for mouse movement - */ +/** + * {@link MouseClass} class provides methods to emulate mouse input + */ +export class MouseClass { + public config: MouseConfig = { + autoDelayMs: 100, mouseSpeed: 1000, }; diff --git a/lib/screen.class.ts b/lib/screen.class.ts index 5d571f89..eb6ba715 100644 --- a/lib/screen.class.ts +++ b/lib/screen.class.ts @@ -46,35 +46,43 @@ function validateSearchRegion(search: Region, screen: Region) { } /** - * {@link ScreenClass} class provides methods to access screen content of a systems main display + * Config object for {@link ScreenClass} class */ -export class ScreenClass { +export interface ScreenConfig { /** - * Config object for {@link ScreenClass} class + * Configures the required matching percentage for template images to be declared as a match */ - public config = { - /** - * Configures the required matching percentage for template images to be declared as a match - */ - confidence: 0.99, + confidence: number; + + /** + * Configure whether to auto highlight all search results or not + */ + autoHighlight: boolean; + /** + * Configure highlighting duration + */ + highlightDurationMs: number; + + /** + * Configure opacity of highlight window + */ + highlightOpacity: number; - /** - * Configure whether to auto highlight all search results or not - */ + /** + * Configures the path from which template images are loaded from + */ + resourceDirectory: string; +} + +/** + * {@link ScreenClass} class provides methods to access screen content of a systems main display + */ +export class ScreenClass { + public config: ScreenConfig = { + confidence: 0.99, autoHighlight: false, - /** - * Configure highlighting duration - */ highlightDurationMs: 500, - - /** - * Configure opacity of highlight window - */ highlightOpacity: 0.25, - - /** - * Configures the path from which template images are loaded from - */ resourceDirectory: cwd(), }; From ee10b708519d6ce9710013d56c8efec7ecaf80a4 Mon Sep 17 00:00:00 2001 From: Simon Hofmann Date: Thu, 27 Oct 2022 00:12:44 +0200 Subject: [PATCH 2/2] (#445) Export config interfaces --- index.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/index.ts b/index.ts index 34c5f059..37f3e21e 100644 --- a/index.ts +++ b/index.ts @@ -1,9 +1,9 @@ import { AssertClass } from "./lib/assert.class"; import { ClipboardClass } from "./lib/clipboard.class"; -import { KeyboardClass } from "./lib/keyboard.class"; -import { MouseClass } from "./lib/mouse.class"; +import { KeyboardClass, KeyboardConfig } from "./lib/keyboard.class"; +import { MouseClass, MouseConfig } from "./lib/mouse.class"; import { createMovementApi } from "./lib/movement.function"; -import { ScreenClass } from "./lib/screen.class"; +import { ScreenClass, ScreenConfig } from "./lib/screen.class"; import { LineHelper } from "./lib/util/linehelper.class"; import { createWindowApi } from "./lib/window.function"; import providerRegistry from "./lib/provider/provider-registry.class"; @@ -13,8 +13,11 @@ export { AssertClass, ClipboardClass, KeyboardClass, + KeyboardConfig, MouseClass, + MouseConfig, ScreenClass, + ScreenConfig, providerRegistry, };