From 720dea67c53b893830157e35edc7abebe8a3a48c Mon Sep 17 00:00:00 2001 From: Simon Hofmann Date: Thu, 27 Oct 2022 00:17:49 +0200 Subject: [PATCH] Feature/445/config interfaces (#446) * (#445) Extracted config interfaces for keyboard, mouse and screen * (#445) Export config interfaces --- index.ts | 9 +++++--- lib/keyboard.class.ts | 15 +++++++++---- lib/mouse.class.ts | 27 +++++++++++++--------- lib/screen.class.ts | 52 +++++++++++++++++++++++++------------------ 4 files changed, 63 insertions(+), 40 deletions(-) diff --git a/index.ts b/index.ts index 34c5f05..37f3e21 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, }; diff --git a/lib/keyboard.class.ts b/lib/keyboard.class.ts index a024581..7a43864 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 9091e77..5f66613 100644 --- a/lib/mouse.class.ts +++ b/lib/mouse.class.ts @@ -8,22 +8,27 @@ import { } from "./mouse-movement.function"; import { ProviderRegistry } from "./provider/provider-registry.class"; +/** + * Config object for {@link MouseClass} class + */ +export interface MouseConfig { + /** + * Configures the delay between single mouse events + */ + autoDelayMs: number; + + /** + * Configures the speed in pixels/second for mouse movement + */ + mouseSpeed: number; +} + /** * {@link MouseClass} class provides methods to emulate mouse input */ export class MouseClass { - /** - * Config object for {@link MouseClass} class - */ - public config = { - /** - * Configures the delay between single mouse events - */ + public config: MouseConfig = { autoDelayMs: 100, - - /** - * Configures the speed in pixels/second for mouse movement - */ mouseSpeed: 1000, }; diff --git a/lib/screen.class.ts b/lib/screen.class.ts index 5d571f8..eb6ba71 100644 --- a/lib/screen.class.ts +++ b/lib/screen.class.ts @@ -45,36 +45,44 @@ function validateSearchRegion(search: Region, screen: Region) { } } +/** + * Config object for {@link ScreenClass} class + */ +export interface ScreenConfig { + /** + * Configures the required matching percentage for template images to be declared as a match + */ + 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; + + /** + * 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 { - /** - * Config object for {@link ScreenClass} class - */ - public config = { - /** - * Configures the required matching percentage for template images to be declared as a match - */ + public config: ScreenConfig = { confidence: 0.99, - - /** - * Configure whether to auto highlight all search results or not - */ 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(), };