### Keysender Example: Automating Notepad with Hotkey Source: https://github.com/krombik/keysender/blob/master/README.md An example demonstrating how to use keysender to automate actions within the Notepad application. It sets Notepad as the work window, registers a global hotkey (F1), and upon activation, moves the mouse, types text, and sends key combinations. ```typescript import { Hardware, GlobalHotkey } from "keysender"; const notepad = new Hardware(null, "Notepad"); // find Notepad handle by className and set it as workwindow new GlobalHotkey({ // register hotkey key: "f1", mode: "once", async action() { if ( (notepad.workwindow.isOpen() || notepad.workwindow.refresh()) && notepad.workwindow.isForeground() ) { notepad.workwindow.setView({ x: 0, y: 0 }); // move workwindow to top left corner of the screen const { width, height } = notepad.workwindow.getView(); await notepad.mouse.humanMoveTo(width / 2, height / 2); // makes human similar mouse movement from current cursor position to middle of "Notepad" window await notepad.keyboard.printText("hello"); // instantly types "hello" await notepad.keyboard.sendKey("space", 50); // press key "space", await for 50 milliseconds, release key "space" await notepad.keyboard.sendKeys(["w", "o", "r", "l", "d"], [25, 50], 50); await notepad.keyboard.sendKey(["ctrl", "s"], 50); // press key combination "ctrl+s", await for 50 milliseconds, release key combination } }, }); ``` -------------------------------- ### Install keysender using npm or yarn Source: https://github.com/krombik/keysender/blob/master/README.md Instructions for installing the keysender Node.js package using either npm or yarn package managers. This typically involves installing build tools first. ```bash npm install --global windows-build-tools npm install -g node-gyp npm install keysender ``` ```bash yarn add keysender ``` -------------------------------- ### Workwindow Position and Size Management Source: https://github.com/krombik/keysender/blob/master/README.md Methods for setting and getting the workwindow's position and size. ```APIDOC ## setView ### Description Sets workwindow position and/or size. ### Method `setView` ### Parameters #### Request Body - **x** (number) - Optional - window x position - **y** (number) - Optional - window y position - **width** (number) - Optional - window width - **height** (number) - Optional - window height ### Request Example ```json { "x": 25 } ``` ```json { "y": 25, "width": 1200 } ``` ```json { "x": 50, "y": 25, "width": 1200, "height": 800 } ``` ## getView ### Description Returns object with workwindow position and size. ### Method `getView` ### Response #### Success Response (200) - **x** (number) - The x-coordinate of the workwindow's position. - **y** (number) - The y-coordinate of the workwindow's position. - **width** (number) - The width of the workwindow. - **height** (number) - The height of the workwindow. ### Response Example ```json { "x": 50, "y": 25, "width": 1200, "height": 800 } ``` ``` -------------------------------- ### Workwindow Get API Source: https://context7.com/krombik/keysender/llms.txt Returns information about the current workwindow. ```APIDOC ## workwindow.get ### Description Returns information about the current workwindow including handle, className, and title. ### Method `workwindow.get() ### Response #### Success Response (200) - **handle** (number) - The window handle. - **className** (string) - The window class name. - **title** (string) - The window title. ### Request Example ```typescript import { Hardware } from "keysender"; const app = new Hardware("Notepad"); const info = app.workwindow.get(); console.log(info); // { handle: 12345, className: 'Notepad', title: 'Untitled - Notepad' } ``` ``` -------------------------------- ### Get Workwindow Information with Keysender Source: https://context7.com/krombik/keysender/llms.txt Retrieves details about the currently targeted work window, including its handle, class name, and title. Requires the 'keysender' library. ```typescript import { Hardware } from "keysender"; const app = new Hardware("Notepad"); const info = app.workwindow.get(); console.log(info); // { handle: 12345, className: 'Notepad', title: 'Untitled - Notepad' } ``` -------------------------------- ### Reassign, unregister, and delete hotkeys Source: https://github.com/krombik/keysender/blob/master/README.md Examples of lifecycle management methods: reassignment changes the key trigger, unregister disables the hotkey while keeping it in memory, and delete removes it entirely. ```typescript import { GlobalHotkey } from "keysender"; const foo = new GlobalHotkey({ key: "num+", mode: "once", action() { console.log("hi"); } }); foo.reassignment("a"); foo.unregister(); foo.delete(); ``` -------------------------------- ### Get Workwindow View Source: https://github.com/krombik/keysender/blob/master/README.md Retrieves the current position and size of the workwindow as an object. ```typescript import { Hardware } from "keysender"; const obj = new Hardware(handle); console.log(obj.workwindow.getView()); ``` -------------------------------- ### Get screen dimensions Source: https://github.com/krombik/keysender/blob/master/README.md Retrieves the current screen size as an object containing width and height properties. ```javascript import { getScreenSize } from "keysender"; console.log(getScreenSize()); ``` -------------------------------- ### Get Current Workwindow Information (TypeScript) Source: https://github.com/krombik/keysender/blob/master/README.md Retrieves detailed information about the currently active workwindow, including its handle, class name, and title. This is useful for verifying the current context or for use in subsequent operations. ```typescript import { Hardware } from "keysender"; const obj = new Hardware("Some title"); // or Virtual console.log(obj.workwindow.get()); // { handle, title, className } ``` -------------------------------- ### Get All Open Windows - TypeScript Source: https://context7.com/krombik/keysender/llms.txt Retrieves an array of all currently open windows on the system. Each window object includes its handle, class name, and title. This function is useful for identifying and selecting specific windows for further automation. ```typescript import { getAllWindows } from "keysender"; const windows = getAllWindows(); console.log(windows); // [ // { handle: 123, className: 'Notepad', title: 'Untitled - Notepad' }, // { handle: 456, className: 'Chrome_WidgetWin_1', title: 'Google Chrome' }, // ... // ] // Find specific window const notepad = windows.find(w => w.className === "Notepad"); if (notepad) { console.log(`Notepad handle: ${notepad.handle}`); } ``` -------------------------------- ### Initialize Hardware and Virtual Automation Classes Source: https://context7.com/krombik/keysender/llms.txt Demonstrates how to instantiate Hardware and Virtual classes to target specific windows by title, class name, or child window hierarchy. Hardware targets foreground applications, while Virtual targets background window messages. ```typescript import { Hardware, Virtual } from "keysender"; const desktop = new Hardware(); const notepad = new Hardware("Notepad"); const app = new Hardware(null, "SomeClassName"); const specific = new Hardware("Some title", "SomeClass"); const child = new Hardware("Parent Title", "ParentClass", "ChildClass", "Child Title"); const background = new Virtual("Background App"); ``` -------------------------------- ### Keysender Constructors: Hardware and Virtual Classes Source: https://github.com/krombik/keysender/blob/master/README.md Demonstrates the different constructor overloads for the Hardware and Virtual classes in the keysender library. These classes offer similar functionalities for keyboard, mouse, and workwindow control, differing in their implementation level (hardware vs. virtual). ```typescript /** Use entire desktop as workwindow */ constructor(); /** Use the first window with {handle} */ constructor(handle: number); /** * Use the first window with {title} and/or {className} and sets it as current workwindow * */ constructor(title: string | null, className?: string | null); /** * Use the first child window with {childClassName} and/or {childTitle} * of window with {parentHandle} and sets it as current workwindow * */ constructor( parentHandle: number, childClassName: string | null, childTitle?: string | null ); /** * Use the first child window with {childClassName} and/or {childTitle} * of the first found window with {parentTitle} and/or {parentClassName} * and sets it as current workwindow * */ constructor( parentTitle: string | null, parentClassName: string | null, childClassName: string | null, childTitle?: string | null ); ``` ```typescript import { Hardware, Virtual } from "keysender"; const foo = new Hardware("Some title"); const bar = new Virtual(null, "SomeClassName"); const foobar = new Hardware( "Some parent title", "SomeParentClassName", "SomeChildClassName" ); ``` -------------------------------- ### Define GlobalHotkey with various modes Source: https://github.com/krombik/keysender/blob/master/README.md Demonstrates how to initialize GlobalHotkey instances using different modes like 'once', 'hold', and 'toggle'. It showcases how to use the action callback, delay, and conditional logic to control execution flow. ```typescript import { GlobalHotkey } from "keysender"; new GlobalHotkey({ key: "num+", mode: "once", action() { console.log("hi"); }, }); new GlobalHotkey({ key: "num*", mode: "hold", action() { console.log("hi"); return true; }, delay: 50, }); let i = 0; new GlobalHotkey({ key: "num/", mode: "toggle", action() { i++; if (i > 50) return false; console.log("hi"); return true; }, }); ``` -------------------------------- ### Keysender Keyboard: sendKey Method Source: https://github.com/krombik/keysender/blob/master/README.md Illustrates how to use the `sendKey` method from the keysender library to simulate pressing and releasing keyboard keys. This method supports single keys, key combinations, and customizable delays after key press and release. ```typescript sendKey( key: KeyboardButton | KeyboardButton[], delayAfterPress?: number | [from: number, to: number], delayAfterRelease?: number | [from: number, to: number] ): Promise; ``` ```typescript import { Hardware } from "keysender"; const obj = new Hardware(handle); // or Virtual await obj.keyboard.sendKey("a"); await obj.keyboard.sendKey("a", 50); await obj.keyboard.sendKey("a", 50, 90); await obj.keyboard.sendKey(["ctrl", "shift", "a"], [25, 50]); ``` -------------------------------- ### Mouse Get Position API Source: https://context7.com/krombik/keysender/llms.txt Returns the current cursor position relative to the workwindow coordinates. ```APIDOC ## mouse.getPos ### Description Returns the current cursor position relative to the workwindow coordinates. ### Method `mouse.getPos() ### Response #### Success Response (200) - **x** (number) - The current X-coordinate. - **y** (number) - The current Y-coordinate. ### Request Example ```typescript import { Hardware } from "keysender"; const app = new Hardware("Notepad"); await app.mouse.moveTo(25, 50); const pos = app.mouse.getPos(); console.log(pos); // { x: 25, y: 50 } // Track mouse position setInterval(() => { const { x, y } = app.mouse.getPos(); console.log(`Mouse at: ${x}, ${y}`); }, 100); ``` ``` -------------------------------- ### Keysender Keyboard: toggleKey Method Source: https://github.com/krombik/keysender/blob/master/README.md Demonstrates the usage of the `toggleKey` method in the keysender library for simulating the pressing or releasing of keys. It allows toggling a key or a combination of keys to a specified state (pressed or released) with optional delays. ```typescript toggleKey( key: KeyboardButton | KeyboardButton[], state: boolean, delay?: number | [from: number, to: number] ): Promise; ``` ```typescript import { Hardware } from "keysender"; const obj = new Hardware(handle); // or Virtual await obj.keyboard.toggleKey("a", true); await obj.keyboard.toggleKey("a", false, 50); await obj.keyboard.toggleKey(["ctrl", "shift", "a"], true, [25, 50]); ``` -------------------------------- ### Get Current Mouse Position (TypeScript) Source: https://github.com/krombik/keysender/blob/master/README.md Retrieves the current position of the mouse cursor relative to the workwindow. Returns an object with 'x' and 'y' coordinates. ```typescript import { Hardware } from "keysender"; const obj = new Hardware(handle); // or Virtual await obj.mouse.moveTo(25, 50); console.log(obj.mouse.getPos()); // {x: 25, y: 50} ``` -------------------------------- ### Workwindow State Management Source: https://github.com/krombik/keysender/blob/master/README.md Methods for managing the foreground status and existence of the workwindow. ```APIDOC ## setForeground ### Description Makes the current workwindow the foreground window. ### Method `setForeground` ## isForeground ### Description Checks if the current workwindow is a foreground window. ### Method `isForeground` ### Response #### Success Response (200) - **isForeground** (boolean) - True if the workwindow is in the foreground, false otherwise. ### Response Example ```json { "isForeground": true } ``` ## isOpen ### Description Checks if the current workwindow exists. ### Method `isOpen` ### Response #### Success Response (200) - **isOpen** (boolean) - True if the workwindow is open, false otherwise. ### Response Example ```json { "isOpen": true } ``` ``` -------------------------------- ### Simulate Human-like Mouse Movement with Keysender Source: https://context7.com/krombik/keysender/llms.txt Provides natural-looking mouse movements by introducing deviations from a straight path, with configurable speed and curvature. Supports cancellation of ongoing movements. Requires the 'keysender' library. ```typescript import { Hardware } from "keysender"; const app = new Hardware("Browser"); // Human-like movement to (500, 300) await app.mouse.humanMoveTo(500, 300); // Slower movement (speed=3, default deviation) await app.mouse.humanMoveTo(200, 400, 3); // Fast movement with high curvature await app.mouse.humanMoveTo(100, 100, 10, 50); // Movement with delay at end await app.mouse.humanMoveTo(300, 200, 5, 30, 100); // Cancel during movement app.mouse.humanMoveTo(1000, 1000, 2); await app.mouse.humanMoveTo.cancelCurrent(); ``` -------------------------------- ### Get Screen Dimensions - TypeScript Source: https://context7.com/krombik/keysender/llms.txt Retrieves the current screen's width and height. This information is valuable for positioning windows or UI elements accurately on the screen, such as centering a window. ```typescript import { getScreenSize } from "keysender"; const screen = getScreenSize(); console.log(screen); // { width: 1920, height: 1080 } // Center a window import { Hardware } from "keysender"; const app = new Hardware("Notepad"); const view = app.workwindow.getView(); app.workwindow.setView({ x: (screen.width - view.width) / 2, y: (screen.height - view.height) / 2 }); ``` -------------------------------- ### Get Current Mouse Position with Keysender Source: https://context7.com/krombik/keysender/llms.txt Retrieves the current coordinates of the mouse cursor relative to the work window. Useful for tracking or conditional actions. Requires the 'keysender' library. ```typescript import { Hardware } from "keysender"; const app = new Hardware("Notepad"); await app.mouse.moveTo(25, 50); const pos = app.mouse.getPos(); console.log(pos); // { x: 25, y: 50 } // Track mouse position setInterval(() => { const { x, y } = app.mouse.getPos(); console.log(`Mouse at: ${x}, ${y}`); }, 100); ``` -------------------------------- ### Execute Keyboard Key Presses Source: https://context7.com/krombik/keysender/llms.txt Shows how to use sendKey to simulate single key presses or complex combinations with configurable delays. This is essential for triggering shortcuts or typing individual characters. ```typescript import { Hardware } from "keysender"; const app = new Hardware("Notepad"); await app.keyboard.sendKey("a"); await app.keyboard.sendKey("enter", 50); await app.keyboard.sendKey("space", 50, 90); await app.keyboard.sendKey(["ctrl", "shift", "s"], 50); await app.keyboard.sendKey(["ctrl", "c"], [25, 50]); ``` -------------------------------- ### Get Pixel Color Source: https://github.com/krombik/keysender/blob/master/README.md Retrieves the color of a pixel at specified coordinates (x, y) from the current work window or the entire screen. The return type can be specified as a hex string, an RGB array, or a decimal number. ```APIDOC ## GET /workwindow/colorAt ### Description Retrieves the pixel color at the specified coordinates (x, y). The color can be returned as a hex string, an RGB array, or a decimal number. ### Method GET ### Endpoint `/workwindow/colorAt` ### Parameters #### Query Parameters - **x** (number) - Required - The x-coordinate of the pixel. - **y** (number) - Required - The y-coordinate of the pixel. - **returnType** (string) - Optional - The format of the returned color. Can be 'string' (default, "rrggbb"), 'array' ([r, g, b]), or 'number' (decimal). ### Request Example ```json { "x": 25, "y": 25, "returnType": "string" } ``` ### Response #### Success Response (200) - **color** (string | array | number) - The color of the pixel in the specified format. #### Response Example ```json { "color": "#FF0000" } ``` ``` -------------------------------- ### GlobalHotkey Constructor Source: https://github.com/krombik/keysender/blob/master/README.md Registers a new global hotkey with specific trigger modes and action callbacks. ```APIDOC ## POST /GlobalHotkey ### Description Creates and registers a new global hotkey listener. ### Method POST ### Parameters #### Request Body - **key** (string) - Required - The keyboard button to trigger the hotkey. - **mode** (string) - Required - The trigger mode: 'once', 'hold', or 'toggle'. - **action** (function) - Required - The callback executed when the hotkey is triggered. - **delay** (number) - Optional - Delay in ms for 'hold' or 'toggle' modes. - **defaultState** (object) - Optional - Initial state object for the hotkey. ### Request Example { "key": "num+", "mode": "once", "action": "() => console.log('hi')" } ``` -------------------------------- ### Print Text with Keysender Source: https://github.com/krombik/keysender/blob/master/README.md Prints a given string to the active window, simulating typing character by character. Users can specify delays after each character is typed and a final delay after the entire text is printed. Supports cancellation. ```typescript import { Hardware } from "keysender"; const obj = new Hardware(handle); // or Virtual await obj.keyboard.printText("hello world"); await obj.keyboard.printText("hello world", 50); await obj.keyboard.printText("hello world", [25, 50], 25); ``` -------------------------------- ### Get Window Children - TypeScript Source: https://context7.com/krombik/keysender/llms.txt Fetches all child windows associated with a given parent window. You can specify the parent by its handle, title, or class name. This is useful for interacting with controls within a specific window. ```typescript import { getWindowChildren } from "keysender"; // Get children by parent handle const children = getWindowChildren(parentHandle); console.log(children); // [ // { handle: 789, className: 'Edit', title: '' }, // { handle: 790, className: 'Button', title: 'OK' }, // ... // ] // Get children by parent title const notepadChildren = getWindowChildren("Notepad"); // Get children by className const explorerChildren = getWindowChildren(null, "CabinetWClass"); // Get children by both title and className const specificChildren = getWindowChildren("Some title", "SomeClass"); ``` -------------------------------- ### Perform Mouse Clicks with Keysender Source: https://context7.com/krombik/keysender/llms.txt Simulates mouse clicks with support for different buttons (left, right, middle, extra) and configurable delays for press and release phases. Dependencies include the 'keysender' library. ```typescript import { Hardware } from "keysender"; const app = new Hardware("Calculator"); // Left click (default) await app.mouse.click(); // Right click with 25ms hold, 15ms after release await app.mouse.click("right", 25, 15); // Middle click await app.mouse.click("middle", 50); // Extra mouse buttons await app.mouse.click("x1", 35); await app.mouse.click("x2", 35); ``` -------------------------------- ### Mouse Click with Keysender Source: https://github.com/krombik/keysender/blob/master/README.md Simulates a mouse click with specified button and delays. Allows configuration of delays after the button press and release. Supports different mouse buttons. ```typescript import { Hardware } from "keysender"; const obj = new Hardware(handle); // or Virtual await obj.mouse.click(); await obj.mouse.click("right", 25, 15); ``` -------------------------------- ### Workwindow Lifecycle Management Source: https://github.com/krombik/keysender/blob/master/README.md Methods for terminating and closing the workwindow. ```APIDOC ## kill ### Description Terminates the current workwindow by killing its thread. ### Method `kill` ## close ### Description Closes the current workwindow by sending a close message to it. ### Method `close` ``` -------------------------------- ### Window Management API Source: https://github.com/krombik/keysender/blob/master/README.md Functions for retrieving information about open windows on the system. ```APIDOC ## getAllWindows ### Description Returns an array of objects containing information about all currently open windows. ### Method ```ts function getAllWindows(): Array<{ handle: number; className: string; title: string; }>; ``` ### Response #### Success Response (Array of Window Objects) - **handle** (number) - The unique handle of the window. - **className** (string) - The class name of the window. - **title** (string) - The title of the window. ### Request Example ```ts import { getAllWindows } from "keysender"; console.log(getAllWindows()); ``` --- ## getWindowChildren ### Description Returns an array of objects containing information about the children of a specified window. ### Method ```ts function getWindowChildren(parentHandle: number): { handle: number; className: string; title: string; }[]; function getWindowChildren( parentTitle: string | null, parentClassName?: string | null ): { handle: number; className: string; title: string; }[]; ``` ### Parameters #### Path Parameters - **parentHandle** (number) - Required - The handle of the parent window. OR - **parentTitle** (string | null) - Required - The title of the parent window. - **parentClassName** (string | null) - Optional - The class name of the parent window. ### Response #### Success Response (Array of Window Objects) - **handle** (number) - The unique handle of the child window. - **className** (string) - The class name of the child window. - **title** (string) - The title of the child window. ### Request Example ```ts import { getWindowChildren } from "keysender"; // Using parent handle console.log(getWindowChildren(parentHandle)); // Using parent title console.log(getWindowChildren("Some title")); // Using parent title and class name console.log(getWindowChildren(null, "SomeClass")); // Using parent title and class name console.log(getWindowChildren("Some title", "SomeClass")); ``` ``` -------------------------------- ### Scroll Mouse Wheel with Keysender Source: https://context7.com/krombik/keysender/llms.txt Simulates mouse wheel scrolling actions, both up and down, with support for multiple steps and delays. Requires the 'keysender' library. ```typescript import { Hardware } from "keysender"; const app = new Hardware("Browser"); // Scroll down (toward user) await app.mouse.scrollWheel(-1); // Scroll up (away from user) await app.mouse.scrollWheel(1); // Scroll multiple steps with delay await app.mouse.scrollWheel(-3, 50); // Scroll up 5 notches await app.mouse.scrollWheel(5, [25, 50]); ``` -------------------------------- ### GlobalHotkey Class Source: https://github.com/krombik/keysender/blob/master/README.md The GlobalHotkey class allows you to register and manage global hotkeys. It supports different modes of operation like 'once', 'toggle', and 'hold', with options for pre-action and post-action callbacks, and state management. ```APIDOC ## GlobalHotkey Registers a hotkey. If any hotkey is already registered for this key, the previous hotkey will be unregistered before the new one is registered. ### Constructor ```typescript new GlobalHotkey(options: HotkeyOptions) ``` ### Options | Field | Description | Default Value | |---|---|---| | `key` | The keyboard key or number representing the hotkey. | | | `mode` | Determines how the hotkey behaves:
- `"once"`: The `action` is called once per key press.
- `"hold"`: The `action` repeats every `delay` milliseconds while the key is pressed or `action` returns `true`.
- `"toggle"`: The `action` starts repeating every `delay` milliseconds after the key is first pressed and stops after the key is pressed a second time or `action` returns `false`. | | | `isEnable?` | A method to check if the hotkey should be executing. | `() => true` | | `before?` | If `mode` is `"hold"` or `"toggle"`, this method is executed before the `action` loop. | | | `action` | The function to be called after the hotkey is pressed. For `"once"` mode, it's called once. For `"hold"` and `"toggle"` modes, it's called repeatedly or until it returns `false`. | | | `after?` | If `mode` is `"hold"` or `"toggle"`, this method is called after the hotkey work ends. The first parameter is the reason for ending, which can be `Reason.BY_ACTION`, `Reason.BY_KEYBOARD`, or a custom reason provided by the `stop` method. | | | `delay?` | The delay in milliseconds for repeating the action in `"hold"` or `"toggle"` modes. | | ### Methods - **`stop(reason?: Reason.BY_STOP | R): Promise | undefined`**: Stops the hotkey execution with an optional reason. - **`reassignment(newKey: KeyboardRegularButton | number): void`**: Reassigns the hotkey to a new key. - **`unregister(): void`**: Unregisters the current hotkey. - **`delete(): void`**: Deletes the hotkey instance. ### Static Methods - **`unregisterAll(): void`**: Unregisters all currently registered hotkeys. - **`deleteAll(): void`**: Deletes all hotkey instances. ### Properties - **`hotkeyState: boolean`**: Indicates whether the hotkey is currently active. - **`state: S`**: Holds the current state of the hotkey, if defined. ### Enums **`Reason`** - `BY_KEYBOARD` - `BY_ACTION` - `BY_STOP` ``` -------------------------------- ### Keyboard Automation API Source: https://github.com/krombik/keysender/blob/master/README.md Methods for simulating keyboard input, including key sequences and text printing. ```APIDOC ## sendKeys ### Description Presses and releases an array of keys or combinations of keys. ### Parameters - **keys** (array) - Required - Array of keys or key combinations. - **afterPressDelay** (number|array) - Optional - Milliseconds to await after each key pressed (Default: 35). - **afterReleaseDelay** (number|array) - Optional - Milliseconds to await after each key released (Default: 35). - **delay** (number|array) - Optional - Milliseconds to await after last key released (Default: 0). ### Request Example await obj.keyboard.sendKeys(["a", "b"], 50, 90); ## printText ### Description Prints the given string of text. ### Parameters - **text** (string) - Required - The string to print. - **delayAfterCharTyping** (number|array) - Optional - Milliseconds to await after each char typing (Default: 0). - **delay** (number|array) - Optional - Milliseconds to await after text printed (Default: 0). ### Request Example await obj.keyboard.printText("hello world", 50); ``` -------------------------------- ### Handle Window Lifecycle with isOpen, close, and kill Source: https://context7.com/krombik/keysender/llms.txt Provides mechanisms to check if a window is active and perform either a graceful close or a forced termination of the process thread. ```typescript import { Hardware } from "keysender"; const app = new Hardware("Notepad"); if (app.workwindow.isOpen()) { app.workwindow.close(); } if (app.workwindow.isOpen()) { app.workwindow.kill(); } ``` -------------------------------- ### vkToString Source: https://github.com/krombik/keysender/blob/master/README.md Converts a virtual key code to its string representation. ```APIDOC ## vkToString ### Description Converts a virtual key code (number) into its corresponding keyboard button name (string). ### Method ```ts function vkToString(virtualKey: number): KeyboardButton; ``` ### Parameters #### Path Parameters - **virtualKey** (number) - Required - The virtual key code to convert. ### Response #### Success Response (string) - Returns the string name of the virtual key. ### Request Example ```ts import { vkToString } from "keysender"; console.log(vkToString(66)); // "b" ``` ``` -------------------------------- ### Low-Level Input Hooking with Keysender Source: https://github.com/krombik/keysender/blob/master/README.md The `LowLevelHook` class provides a way to register callbacks for keyboard and mouse events without blocking the input. It supports different modes like 'once', 'toggle', and 'hold', and allows for custom states and reasons for stopping the hook. It is similar to `GlobalHotkey` but offers more granular control and supports mouse events. ```typescript import { LowLevelHook } from "keysender"; new LowLevelHook({ device: "keyboard", button: "a", mode: "hold", action() { console.log("'a' pressed"); return true; }, }); new LowLevelHook({ device: "mouse", button: "left", mode: "once", action() { console.log("left mouse button was pressed"); }, }); ``` -------------------------------- ### Workwindow State and Closing Source: https://context7.com/krombik/keysender/llms.txt Check if a workwindow exists and provides methods to close or terminate it. ```APIDOC ## workwindow.isOpen, close, and kill ### Description Checks if a window exists and provides methods to close or kill it. ### Method - `isOpen()`: Returns true if the workwindow exists, false otherwise. - `close()`: Gracefully closes the workwindow by sending a close message. - `kill()`: Forcefully terminates the workwindow's process. ### Request Example ```typescript import { Hardware } from "keysender"; const app = new Hardware("Notepad"); // Check if window exists if (app.workwindow.isOpen()) { console.log("Window is open"); // Gracefully close (sends close message) app.workwindow.close(); } // Force kill if needed if (app.workwindow.isOpen()) { app.workwindow.kill(); // Terminates the window's thread } ``` ### Response Example `isOpen()` returns a boolean value. `close()` and `kill()` do not return values upon success. ``` -------------------------------- ### LowLevelHook: Keyboard and Mouse Event Hooks Source: https://context7.com/krombik/keysender/llms.txt Creates low-level hooks for keyboard and mouse events, allowing multiple callbacks for the same button without blocking original input. Supports 'hold' and 'once' modes. Events can be listened to using the 'on' method, and all hooks can be deleted. ```typescript import { LowLevelHook } from "keysender"; // Hook keyboard key new LowLevelHook({ device: "keyboard", button: "a", mode: "hold", action() { console.log("'a' is being pressed"); return true; } }); // Hook mouse button new LowLevelHook({ device: "mouse", button: "left", mode: "once", action() { console.log("Left mouse button clicked"); } }); // Simple event listener with on() method const unlisten = LowLevelHook.on("mouse", "left", true, () => { console.log("Left mouse button pressed"); }); // Listen for key release LowLevelHook.on("keyboard", "a", false, () => { console.log("'a' was released"); }); // Listen for mouse wheel LowLevelHook.on("mouse", "wheel", true, () => { console.log("Wheel scrolled forward"); }); LowLevelHook.on("mouse", "wheel", false, () => { console.log("Wheel scrolled backward"); }); // Stop listening unlisten(); // Delete all hooks LowLevelHook.deleteAll(); ``` -------------------------------- ### Send Sequential Keyboard Inputs Source: https://context7.com/krombik/keysender/llms.txt Demonstrates sending arrays of keys or combinations sequentially. Includes support for custom timing and canceling long-running sequences. ```typescript import { Hardware } from "keysender"; const app = new Hardware("Notepad"); await app.keyboard.sendKeys(["a", "b", "c", "d", "e"]); await app.keyboard.sendKeys(["h", "e", "l", "l", "o"], 50); await app.keyboard.sendKeys(["w", "o", "r", "l", "d"], 50, 90); await app.keyboard.sendKeys(["h", "i", "space", ["ctrl", "b"], "t", "e", "x", "t", ["ctrl", "b"]], [25, 50], 25, 45); app.keyboard.sendKeys(["a", "b", "c", "d", "e", "f", "g"], 100); await app.keyboard.sendKeys.cancelCurrent(); ``` -------------------------------- ### Set Target Workwindow with Keysender Source: https://context7.com/krombik/keysender/llms.txt Allows changing the active window for automation tasks by specifying window handles, class names, or titles. Can also target the desktop or child windows. Requires the 'keysender' library. ```typescript import { Hardware } from "keysender"; const automation = new Hardware("Notepad"); // Switch to different window by className automation.workwindow.set(null, "SomeClass"); // Switch by window handle automation.workwindow.set(12345); // Switch to desktop automation.workwindow.set(); // Switch to child window automation.workwindow.set("Parent Title", "ParentClass", "ChildClass"); ``` -------------------------------- ### Simulate Human-like Mouse Movement (TypeScript) Source: https://github.com/krombik/keysender/blob/master/README.md Simulates a human-like mouse movement from the current cursor position to a target [x, y] within the current workwindow. Allows customization of speed and curvature. It also provides a method to cancel ongoing movements. ```typescript import { Hardware } from "keysender"; const obj = new Hardware(handle); // or Virtual await obj.mouse.humanMoveTo(25, 25); // To cancel an ongoing movement: // await obj.mouse.humanMoveTo.cancelCurrent(); ``` -------------------------------- ### Unregister all hotkeys Source: https://github.com/krombik/keysender/blob/master/README.md Demonstrates the static method to unregister every active hotkey in the application. ```javascript import { GlobalHotkey } from "keysender"; GlobalHotkey.unregisterAll(); ``` -------------------------------- ### Render text to image using Keysender Source: https://github.com/krombik/keysender/blob/master/README.md Converts a string into an image buffer using a specified font file. Supports .ttf and .otf formats with configurable options for anti-aliasing, colors, and output formats. ```typescript import { textToImg } from "keysender"; const img1 = textToImg("Hello World!", "./path/to/font.ttf", 12); const img2 = textToImg("Hello World!", "./path/to/font.otf", 24, { enableAntiAliasing: false, format: "grey", }); const img3 = textToImg("Hello World!", "./path/to/font.otf", 36, { enableActualHeight: true, color: "ff0000", backgroundColor: [0, 255, 0], }); ``` -------------------------------- ### Workwindow Set API Source: https://context7.com/krombik/keysender/llms.txt Changes the current workwindow target. ```APIDOC ## workwindow.set ### Description Changes the current workwindow target. Allows switching between windows without creating new instances. ### Method `workwindow.set(handle?, className?, childClassName?) ### Parameters - **handle** (number) - Optional - The window handle. - **className** (string) - Optional - The window class name. - **childClassName** (string) - Optional - The child window class name. ### Request Example ```typescript import { Hardware } from "keysender"; const automation = new Hardware("Notepad"); // Switch to different window by className automation.workwindow.set(null, "SomeClass"); // Switch by window handle automation.workwindow.set(12345); // Switch to desktop automation.workwindow.set(); // Switch to child window automation.workwindow.set("Parent Title", "ParentClass", "ChildClass"); ``` ``` -------------------------------- ### Refresh Workwindow Target with Keysender Source: https://context7.com/krombik/keysender/llms.txt Attempts to re-acquire the target work window if it has been closed and reopened, using the initial parameters. Useful for maintaining automation sessions. Requires the 'keysender' library. ```typescript import { Hardware } from "keysender"; const notepad = new Hardware(null, "Notepad"); // Check if window still exists, try to find it again if not if (!notepad.workwindow.isOpen()) { const found = notepad.workwindow.refresh(); if (found) { console.log("Window found again"); } else { console.log("Window not available"); } } ``` -------------------------------- ### Retrieve window information Source: https://github.com/krombik/keysender/blob/master/README.md Functions to list all open windows or retrieve child windows based on handles, titles, or class names. Returns arrays of objects containing window metadata. ```typescript import { getAllWindows, getWindowChildren } from "keysender"; console.log(getAllWindows()); console.log(getWindowChildren(parentHandle)); console.log(getWindowChildren("Some title")); console.log(getWindowChildren(null, "SomeClass")); console.log(getWindowChildren("Some title", "SomeClass")); ``` -------------------------------- ### Manage hotkey state Source: https://github.com/krombik/keysender/blob/master/README.md Demonstrates how to maintain and modify internal state within a hotkey instance, accessible via 'this.state' inside callbacks. ```typescript type State = { counter: number }; const hotkey = new GlobalHotkey({ key: "f1", mode: "toggle", action() { this.state.counter++; console.log(this.state.counter); return true; }, defaultState: { counter: 0 }, }); ``` -------------------------------- ### Workwindow View Management Source: https://context7.com/krombik/keysender/llms.txt Manage the position and dimensions of an application's workwindow. ```APIDOC ## workwindow.setView and getView ### Description Sets or gets the workwindow position and dimensions. ### Method - `getView()`: Returns the current workwindow dimensions and position. - `setView(options)`: Sets the workwindow position and/or size. ### Parameters #### `setView` Options - **x** (number) - Optional - The x-coordinate for the top-left corner. - **y** (number) - Optional - The y-coordinate for the top-left corner. - **width** (number) - Optional - The width of the workwindow. - **height** (number) - Optional - The height of the workwindow. ### Request Example ```typescript import { Hardware } from "keysender"; const app = new Hardware("Notepad"); // Get current view const view = app.workwindow.getView(); console.log(view); // { x: 100, y: 100, width: 800, height: 600 } // Set only position app.workwindow.setView({ x: 0, y: 0 }); // Set only size app.workwindow.setView({ width: 1024, height: 768 }); // Set both position and size app.workwindow.setView({ x: 50, y: 25, width: 1200, height: 800 }); // Center window on screen import { getScreenSize } from "keysender"; const screen = getScreenSize(); app.workwindow.setView({ x: (screen.width - view.width) / 2, y: (screen.height - view.height) / 2 }); ``` ### Response Example `getView()` response: ```json { "x": 100, "y": 100, "width": 800, "height": 600 } ``` ``` -------------------------------- ### Mouse Human Move To API Source: https://context7.com/krombik/keysender/llms.txt Simulates human-like mouse movement with configurable speed and curvature. ```APIDOC ## mouse.humanMoveTo ### Description Simulates human-like mouse movement with configurable speed and curvature. Movement path includes natural deviation from a straight line. ### Method `mouse.humanMoveTo(x, y, speed?, curvature?, delay?) ### Parameters - **x** (number) - Required - The target X-coordinate. - **y** (number) - Required - The target Y-coordinate. - **speed** (number) - Optional - Movement speed (lower is slower, default is 5). - **curvature** (number) - Optional - Curvature of the movement path (higher means more curve, default is 10). - **delay** (number) - Optional - Delay in milliseconds after the movement completes. ### Request Example ```typescript import { Hardware } from "keysender"; const app = new Hardware("Browser"); // Human-like movement to (500, 300) await app.mouse.humanMoveTo(500, 300); // Slower movement (speed=3, default deviation) await app.mouse.humanMoveTo(200, 400, 3); // Fast movement with high curvature await app.mouse.humanMoveTo(100, 100, 10, 50); // Movement with delay at end await app.mouse.humanMoveTo(300, 200, 5, 30, 100); // Cancel during movement app.mouse.humanMoveTo(1000, 1000, 2); await app.mouse.humanMoveTo.cancelCurrent(); ``` ``` -------------------------------- ### Stop and manage hotkey execution Source: https://github.com/krombik/keysender/blob/master/README.md Shows how to programmatically stop a hotkey's action loop using the stop method and handle custom reasons in the after callback. ```typescript import { GlobalHotkey } from "keysender"; const hotkey = new GlobalHotkey({ key: "num-", mode: "toggle", action() { return true; }, after(reason) { if (reason === "someReason") console.log("stopped"); }, }); new GlobalHotkey({ key: "num+", mode: "once", async action() { await hotkey.stop("someReason"); console.log("num- action was stopped"); }, }); ``` -------------------------------- ### reassignment Source: https://github.com/krombik/keysender/blob/master/README.md Updates the key associated with an existing hotkey instance. ```APIDOC ## PUT /GlobalHotkey/reassignment ### Description Changes the trigger key for an existing hotkey instance. ### Parameters #### Request Body - **newHotkey** (string|number) - Required - The new key to assign. ``` -------------------------------- ### Mouse Automation API Source: https://github.com/krombik/keysender/blob/master/README.md Methods for simulating mouse input, including clicks, button toggling, and cursor movement. ```APIDOC ## click ### Description Simulates a mouse button click. ### Parameters - **button** (string) - Optional - Mouse button name (Default: "left"). - **delayAfterPress** (number|array) - Optional - Milliseconds to await after button pressed (Default: 35). - **delayAfterRelease** (number|array) - Optional - Milliseconds to await after button released (Default: 0). ## toggle ### Description Switches the state of a mouse button (press or release). ### Parameters - **button** (string) - Required - Mouse button name. - **state** (boolean) - Required - true for press, false for release. - **delay** (number|array) - Optional - Milliseconds to await after switching state (Default: 0). ## moveTo ### Description Moves the mouse cursor to specific coordinates within the workwindow. ### Parameters - **x** (number) - Required - X coordinate. - **y** (number) - Required - Y coordinate. - **delay** (number|array) - Optional - Milliseconds to await after movement (Default: 0). ``` -------------------------------- ### Manage Workwindow Geometry with setView and getView Source: https://context7.com/krombik/keysender/llms.txt Retrieves the current window dimensions and position, or updates them. Supports partial updates for size or position and can be used to center windows relative to screen resolution. ```typescript import { Hardware, getScreenSize } from "keysender"; const app = new Hardware("Notepad"); const view = app.workwindow.getView(); app.workwindow.setView({ x: 0, y: 0 }); app.workwindow.setView({ width: 1024, height: 768 }); const screen = getScreenSize(); app.workwindow.setView({ x: (screen.width - view.width) / 2, y: (screen.height - view.height) / 2 }); ``` -------------------------------- ### Capture Window Screenshots Source: https://context7.com/krombik/keysender/llms.txt Captures visual data from the window or desktop. Supports various color formats like RGBA, BGRA, grayscale, and monochrome, with optional region-based cropping. ```typescript import { Hardware } from "keysender"; const app = new Hardware("Notepad"); const screenshot = app.workwindow.capture(); const region = app.workwindow.capture({ x: 25, y: 25, width: 500, height: 500 }); const mono = app.workwindow.capture({ x: 25, y: 25, width: 500, height: 500 }, "monochrome", 200); ``` -------------------------------- ### Control Window Foreground State Source: https://context7.com/krombik/keysender/llms.txt Methods to bring a window to the foreground and verify its active status. Useful for ensuring input commands are sent to the correct target window. ```typescript import { Hardware } from "keysender"; const app = new Hardware("Notepad"); app.workwindow.setForeground(); if (app.workwindow.isForeground()) { await app.keyboard.printText("Window is active!"); } ``` -------------------------------- ### getScreenSize Source: https://github.com/krombik/keysender/blob/master/README.md Retrieves the current screen dimensions. ```APIDOC ## getScreenSize ### Description Returns an object containing the width and height of the screen. ### Method ```ts function getScreenSize(): size; ``` ### Response #### Success Response (Size Object) - **width** (number) - The width of the screen in pixels. - **height** (number) - The height of the screen in pixels. ### Request Example ```js import { getScreenSize } from "keysender"; console.log(getScreenSize()); ``` ```