/* tslint:disable */ /* eslint-disable */ /* auto-generated by NAPI-RS */ /** 匹配区域定义 */ export interface MatchRegion { /** 区域左上角 x 坐标 */ x: number /** 区域左上角 y 坐标 */ y: number /** 区域宽度 */ width: number /** 区域高度 */ height: number } /** 图片元信息 */ export interface ImageMetadata { /** 图片宽度 */ width: number /** 图片高度 */ height: number /** 通道数(固定为4,RGBA) */ channels: number /** 每个像素的字节数(固定为4) */ bytesPerPixel: number /** 数据总字节数 */ dataSize: number } /** 匹配选项(ImageData 使用) */ export interface MatchOptionsJs { /** 匹配阈值 (0.0-1.0),低于此值视为未找到,默认 0.8 */ threshold?: number /** 匹配区域列表,若为空则在整个图片中匹配 */ regions?: Array } /** 匹配选项(Window 专用) */ export interface WindowMatchOptions { /** 匹配阈值 (0.0-1.0),低于此值视为未找到,默认 0.8 */ threshold?: number /** 匹配区域列表,若为空则在整个图片中匹配 */ regions?: Array /** * 图片来源: * - `'window'`(默认):截取当前窗口 * - `'screen'`:截取窗口所在显示器的整屏 */ from?: 'window' | 'screen' } /** 匹配选项(Monitor 专用) */ export interface MonitorMatchOptions { /** 匹配阈值 (0.0-1.0),低于此值视为未找到,默认 0.8 */ threshold?: number /** 匹配区域列表,若为空则在整个图片中匹配 */ regions?: Array } /** 文字查找选项(ImageData 使用) */ export interface FindTextOptions { /** 查找区域列表,若为空则在全图查找 */ regions?: Array /** 排除文字,若同一行中包含此文字则排除该匹配结果 */ notText?: string /** 匹配索引,默认为 0(第一个匹配)。负数表示倒数:-1 最后一个,-2 倒数第二个 */ index?: number } /** 文字查找选项(Window 专用) */ export interface WindowFindTextOptions { /** 查找区域列表,若为空则在全图查找 */ regions?: Array /** 排除文字,若同一行中包含此文字则排除该匹配结果 */ notText?: string /** * 图片来源: * - `'window'`(默认):截取当前窗口 * - `'screen'`:截取窗口所在显示器的整屏 */ from?: 'window' | 'screen' /** 匹配索引,默认为 0(第一个匹配)。负数表示倒数:-1 最后一个,-2 倒数第二个 */ index?: number } /** 文字查找选项(Monitor 专用) */ export interface MonitorFindTextOptions { /** 查找区域列表,若为空则在全图查找 */ regions?: Array /** 排除文字,若同一行中包含此文字则排除该匹配结果 */ notText?: string /** 匹配索引,默认为 0(第一个匹配)。负数表示倒数:-1 最后一个,-2 倒数第二个 */ index?: number } /** 文字识别选项(ImageData 使用) */ export interface RecognizeTextOptions { /** 识别区域列表,若为空则识别全图 */ regions?: Array } /** 文字识别选项(Window 专用) */ export interface WindowRecognizeTextOptions { /** 识别区域列表,若为空则识别全图 */ regions?: Array /** * 图片来源: * - `'window'`(默认):截取当前窗口 * - `'screen'`:截取窗口所在显示器的整屏 */ from?: 'window' | 'screen' } /** 文字识别选项(Monitor 专用) */ export interface MonitorRecognizeTextOptions { /** 识别区域列表,若为空则识别全图 */ regions?: Array } /** 等待选项(Window 专用) */ export interface WindowWaitOptions { /** 查找区域列表,若为空则在全图查找 */ regions?: Array /** 等待超时时间(毫秒),默认 3000 */ timeout?: number /** 匹配阈值 (0.0-1.0),低于此值视为未找到,默认 0.8(仅用于 waitIcon/clickIcon) */ threshold?: number /** 排除文字,若同一行中包含此文字则排除该匹配结果(仅用于 waitText/clickText) */ notText?: string /** * 图片来源: * - `'window'`(默认):截取当前窗口 * - `'screen'`:截取窗口所在显示器的整屏 */ from?: 'window' | 'screen' /** 匹配索引,默认为 0(第一个匹配)。负数表示倒数:-1 最后一个,-2 倒数第二个(仅用于 waitText/clickText) */ index?: number } /** 等待选项(Monitor 专用) */ export interface MonitorWaitOptions { /** 查找区域列表,若为空则在全图查找 */ regions?: Array /** 等待超时时间(毫秒),默认 3000 */ timeout?: number /** 匹配阈值 (0.0-1.0),低于此值视为未找到,默认 0.8(仅用于 waitIcon/clickIcon) */ threshold?: number /** 排除文字,若同一行中包含此文字则排除该匹配结果(仅用于 waitText/clickText) */ notText?: string /** 匹配索引,默认为 0(第一个匹配)。负数表示倒数:-1 最后一个,-2 倒数第二个(仅用于 waitText/clickText) */ index?: number } /** 等待选项(兼容旧代码,与 WindowWaitOptions 相同) */ export interface WaitOptions { /** 查找区域列表,若为空则在全图查找 */ regions?: Array /** 等待超时时间(毫秒),默认 3000 */ timeout?: number /** 匹配阈值 (0.0-1.0),低于此值视为未找到,默认 0.8(仅用于 waitIcon/clickIcon) */ threshold?: number /** 排除文字,若同一行中包含此文字则排除该匹配结果(仅用于 waitText/clickText) */ notText?: string /** * 图片来源: * - `'window'`(默认):截取当前窗口 * - `'screen'`:截取窗口所在显示器的整屏 */ from?: 'window' | 'screen' /** 匹配索引,默认为 0(第一个匹配)。负数表示倒数:-1 最后一个,-2 倒数第二个(仅用于 waitText/clickText) */ index?: number } /** 图标匹配结果 */ export interface MatchResult { /** 是否找到匹配 */ found: boolean /** 相似度分数 (0.0-1.0) */ score: number /** 匹配位置 x 坐标(逻辑屏幕坐标,可直接用于 Mouse.moveTo) */ x: number /** 匹配位置 y 坐标(逻辑屏幕坐标,可直接用于 Mouse.moveTo) */ y: number /** 模板宽度 */ width: number /** 模板高度 */ height: number /** 相对于当前窗口/屏幕左上角的 x 坐标 */ relX: number /** 相对于当前窗口/屏幕左上角的 y 坐标 */ relY: number } /** 文字识别结果 */ export interface TextRecognitionResult { /** 识别出的文字内容 */ text: string /** 文字区域左上角 x 坐标(逻辑屏幕坐标,可直接用于 Mouse.moveTo) */ x: number /** 文字区域左上角 y 坐标(逻辑屏幕坐标,可直接用于 Mouse.moveTo) */ y: number /** 文字区域宽度 */ width: number /** 文字区域高度 */ height: number /** 识别置信度 (0.0-1.0) */ confidence: number /** 相对于当前窗口/屏幕左上角的 x 坐标 */ relX: number /** 相对于当前窗口/屏幕左上角的 y 坐标 */ relY: number } /** 截图时可选的目标尺寸,配置后会将截取到的图像缩放到指定宽高 */ export interface CaptureSize { /** 目标宽度(像素) */ width: number /** 目标高度(像素) */ height: number } /** 截取区域(逻辑像素),仅截取该矩形范围 */ export interface CaptureRegion { /** 区域左上角 x(相对截图画布左上角,逻辑像素) */ x: number /** 区域左上角 y(逻辑像素) */ y: number /** 区域宽度(逻辑像素) */ width: number /** 区域高度(逻辑像素) */ height: number } /** 点击结果 */ export interface ClickResult { /** 点击的 x 坐标(屏幕坐标) */ x: number /** 点击的 y 坐标(屏幕坐标) */ y: number /** 相对于当前窗口/屏幕左上角的 x 坐标 */ relX: number /** 相对于当前窗口/屏幕左上角的 y 坐标 */ relY: number } /** captureImage 的选项对象,便于后续扩展更多参数 */ export interface CaptureImageOptions { /** 目标尺寸,配置后会将截取到的图像缩放到指定宽高 */ size?: CaptureSize | null /** * 图片来源(仅对 Window.captureImage 有效): * - `'window'`(默认):截取当前窗口 * - `'screen'`:截取窗口所在显示器的整屏,可用 getBounds() 与显示器范围计算裁剪区域,再通过 image.crop() 得到窗口截图;超出当前显示器范围的部分不会出现在图中 */ from?: 'window' | 'screen' | null /** 仅截取该区域(逻辑像素),不填则截取全图;仅对 Window.captureImage 有效 */ region?: CaptureRegion | null /** * 默认为 true,若存在 DPI 缩放(scaleFactor > 1),则自动将图像缩放到逻辑像素宽高(与 getSize/getBounds 一致) * 适用于 Window.captureImage 和 Monitor.captureImage */ autoSize?: boolean | null /** * 文件保存路径,若指定则自动将截图保存到该文件 * 根据文件扩展名自动识别格式(.png/.jpg/.jpeg/.bmp),格式不支持则报错 */ writeFilePath?: string | null } /** 窗口变化监听的选项 */ export interface WindowWatchOptionsJs { /** * 变化检测的灵敏度阈值 (0.0-1.0),默认 0.0 * * - 0.0 表示跳过对比,每次轮询都触发回调(最敏感,最低延迟) * - 大于 0.0 时,仅当像素变化比例超过阈值才触发回调 */ threshold?: number /** * 最小变化像素数(逻辑像素),默认 0(不使用) * * - 0 表示不使用此条件,仅靠 threshold 控制 * - 大于 0 时,估算的原图逻辑像素变化数须 >= 该值才触发回调 * - 与 threshold 为 AND 关系:两者均满足时才触发 */ minChangedPixels?: number /** * 单像素最小通道差异(0-255),默认 30,用于过滤截图噪声 * * - 仅当像素的 R/G/B 任一通道差值 >= 该值才算“变化” * - 设为 0 则任意微小差异都计入(最敏感,但噪声也会触发) * - 设为 1 则任意像素差异都计入(精确字节比较) */ minPixelDiff?: number /** 图片来源:'window'(默认)或 'screen' */ from?: 'window' | 'screen' /** 仅在指定多个区域检测变化(逻辑像素,相对窗口);不填或空数组表示全窗口 */ regions?: Array | null } /** * 窗口内容变化回调信息 */ export interface WindowChangeInfo { /** 降采样相邻帧对比得到的像素变化比例,约 0.0–1.0;帧尺寸不一致时为 `1` */ changeRatio: number /** 估算的原图逻辑像素变化数;帧尺寸不一致时为 `4294967295` (u32::MAX) */ changedPixels: number } /** * 窗口内容变化回调(启动时先采一帧建基线,不调用本回调;之后仅在检测到相对上一帧的变化时调用) * @param info 变化详情,含 `changeRatio`(变化比例)和 `changedPixels`(估算变化像素数) */ export type WindowChangeCallback = (info: WindowChangeInfo) => void /** 窗口变化监听器句柄,用于停止监听 */ export interface WindowWatcher { /** 停止监听,释放底层资源 */ stop(): void /** 检查是否仍在运行 */ isRunning(): boolean /** * 在监听过程中合并更新选项(仅传入的字段会覆盖当前值,未传的字段保持不变); * 下一轮轮询起生效;若已调用 stop() 则抛出错误。 */ changeOptions(options: WindowWatchOptionsJs): void } /** 窗口尺寸信息 */ export interface WindowSize { /** 窗口宽度 */ width: number /** 窗口高度 */ height: number } /** 窗口边界信息 */ export interface WindowBounds { /** 窗口 x 坐标 */ x: number /** 窗口 y 坐标 */ y: number /** 窗口宽度 */ width: number /** 窗口高度 */ height: number } /** Monitor.toJSON() 返回的 JSON 对象 */ export interface MonitorToJson { id: number name: string x: number y: number width: number height: number isPrimary: boolean scaleFactor: number } /** Window.toJSON() 返回的 JSON 对象 */ export interface WindowToJson { id: number pid: number parentId: number appName: string title: string x: number y: number width: number height: number isMinimized: boolean isMaximized: boolean isFocused: boolean monitorId?: number } /** 鼠标按钮枚举,用于 click / doubleClick / down / up 的 button 参数,如 Mouse.click(MouseButton.Right) */ export const MouseButton: { readonly Left: 'left' readonly Right: 'right' readonly Middle: 'middle' readonly Back: 'back' readonly Forward: 'forward' } /** 鼠标按钮类型,可直接用字符串或 MouseButton 枚举 */ export type MouseButtonType = 'left' | 'right' | 'middle' | 'back' | 'forward' /** 鼠标位置,Mouse.position() 的返回值 */ export interface MousePosition { x: number y: number } /** Mouse 类 - 鼠标控制 */ export declare class Mouse { /** * 移动鼠标到指定坐标 * @param x - 目标 x 坐标 * @param y - 目标 y 坐标 * @param duration - 可选,移动动画持续时间(秒)。默认为 0,表示瞬间移动。如果设置 > 0,鼠标将以平滑动画的方式移动到目标点 */ static moveTo(x: number, y: number, duration?: number | null): Promise /** * 相对移动鼠标 * @param dx - X 轴偏移量(正数向右,负数向左) * @param dy - Y 轴偏移量(正数向下,负数向上) * @param duration - 可选,移动动画持续时间(秒)。默认为 0,表示瞬间移动 */ static moveRel(dx: number, dy: number, duration?: number | null): Promise /** 点击鼠标按钮。button 可选,可用 MouseButton.Left / 'left' 等,默认左键 */ static click(button?: MouseButtonType | null): Promise /** 双击鼠标按钮。button 取值同 click */ static doubleClick(button?: MouseButtonType | null): Promise /** 按下鼠标按钮。button 取值同 click */ static down(button?: MouseButtonType | null): Promise /** 释放鼠标按钮。button 取值同 click */ static up(button?: MouseButtonType | null): Promise /** 滚动鼠标滚轮。deltaX:正数向右、负数向左;deltaY:正数向上、负数向下。如 scroll(0, 3) 向上滚 */ static scroll(deltaX?: number | undefined | null, deltaY?: number | undefined | null): Promise /** 获取当前鼠标位置,返回 { x, y } */ static position(): Promise } /** * 键盘按键枚举,用于 Keyboard.down / up / click / sequence 的 key 参数。 * 如 Keyboard.click(Key.Enter)、Keyboard.sequence([Key.Ctrl, Key.C]) */ export const Key: { readonly A: string readonly B: string readonly C: string readonly D: string readonly E: string readonly F: string readonly G: string readonly H: string readonly I: string readonly J: string readonly K: string readonly L: string readonly M: string readonly N: string readonly O: string readonly P: string readonly Q: string readonly R: string readonly S: string readonly T: string readonly U: string readonly V: string readonly W: string readonly X: string readonly Y: string readonly Z: string readonly Num0: string readonly Num1: string readonly Num2: string readonly Num3: string readonly Num4: string readonly Num5: string readonly Num6: string readonly Num7: string readonly Num8: string readonly Num9: string readonly F1: string readonly F2: string readonly F3: string readonly F4: string readonly F5: string readonly F6: string readonly F7: string readonly F8: string readonly F9: string readonly F10: string readonly F11: string readonly F12: string readonly Enter: string readonly Return: string readonly Escape: string readonly Esc: string readonly Tab: string readonly Space: string readonly Backspace: string readonly Delete: string readonly Insert: string readonly Control: string readonly Ctrl: string readonly Shift: string readonly Alt: string readonly Meta: string readonly Command: string readonly Win: string readonly Left: string readonly Right: string readonly Up: string readonly Down: string readonly Home: string readonly End: string readonly PageUp: string readonly PageDown: string readonly Numpad0: string readonly Numpad1: string readonly Numpad2: string readonly Numpad3: string readonly Numpad4: string readonly Numpad5: string readonly Numpad6: string readonly Numpad7: string readonly Numpad8: string readonly Numpad9: string readonly NumpadAdd: string readonly NumpadSubtract: string readonly NumpadMultiply: string readonly NumpadDivide: string readonly NumpadDecimal: string readonly NumpadEnter: string [k: string]: string } /** Keyboard 类 - 键盘控制 */ export declare class Keyboard { /** 按下键盘按键。key 可用 Key 枚举如 Key.Enter,或字符串如 'enter' */ static down(key: string): Promise /** 释放键盘按键。key 可用 Key 枚举或字符串 */ static up(key: string): Promise /** 点击键盘按键(按下后立即释放)。key 可用 Key 枚举或字符串 */ static click(key: string): Promise /** 输入文本字符串 */ static typeText(text: string): Promise /** 执行按键序列。keys 可用 Key 枚举如 [Key.Ctrl, Key.C] */ static sequence(keys: Array): Promise } /** 图片数据结构 */ export declare class ImageData { /** * 从文件路径加载图片(静态工厂方法) * * # Arguments * * * `file_path` - 图片文件路径 * * # Example * * ```javascript * const image = await ImageData.fromFile('screenshot.png'); * console.log(`Image size: ${image.width}x${image.height}`); * ``` */ static fromFile(filePath: string): Promise /** * 从 Buffer 解码图片(静态工厂方法) * * # Arguments * * * `buffer` - 包含图片数据的 Buffer * * # Example * * ```javascript * const buffer = fs.readFileSync('screenshot.png'); * const image = await ImageData.fromBuffer(buffer); * console.log(`Image size: ${image.width}x${image.height}`); * ``` */ static fromBuffer(buffer: Buffer): Promise /** * 从 base64 字符串解码图片(静态工厂方法) * * 支持纯 base64 字符串或 data URI(如 `data:image/png;base64,...`) * * # Example * * ```javascript * const image = await ImageData.fromBase64(base64String); * const image2 = await ImageData.fromBase64('data:image/png;base64,iVBOR...'); * ``` */ static fromBase64(base64: string): Promise /** 获取图片宽度 */ get width(): number /** 获取图片高度 */ get height(): number /** * 获取原始像素数据(RGBA 格式) * * 返回包含所有像素的字节数组,每个像素4个字节(R, G, B, A) * 数组长度为 width * height * 4 * * # Example * * ```javascript * const image = await ImageData.fromFile('test.png'); * const rawData = image.getRawData(); * console.log(`Data size: ${rawData.length} bytes`); * console.log(`First pixel: R=${rawData[0]}, G=${rawData[1]}, B=${rawData[2]}, A=${rawData[3]}`); * ``` */ getRawData(): Buffer /** * 获取图片元信息 * * 返回包含图片尺寸、通道数等元数据的对象 * * # Example * * ```javascript * const image = await ImageData.fromFile('test.png'); * const meta = image.metadata(); * console.log(`Size: ${meta.width}x${meta.height}`); * console.log(`Channels: ${meta.channels}, Data size: ${meta.dataSize} bytes`); * ``` */ metadata(): ImageMetadata /** 转换为 PNG 格式(异步) */ toPng(): Promise /** 转换为 JPEG 格式(异步) */ toJpeg(): Promise /** 转换为 BMP 格式(异步) */ toBmp(): Promise /** 裁剪图片(异步) */ crop(x: number, y: number, width: number, height: number): Promise /** 缩放图片(异步) */ resize(newWidth: number, newHeight: number): Promise /** 在图片中查找模板图标(异步) */ findIcon(template: ImageData, options?: MatchOptionsJs | undefined | null): Promise /** * 识别图片中的文字(异步) * * 使用 PP-OCRv5 模型进行文字检测和识别,支持中文、英文、日文 * * # Arguments * * * `options` - 识别选项(可选),可指定识别区域以提升速度 * * # Example * * ```javascript * const image = await ImageData.fromFile('screenshot.png'); * const results = await image.recognizeText(); * for (const result of results) { * console.log(`Text: ${result.text}, Position: (${result.x}, ${result.y})`); * } * * // 在指定区域中识别 * const results2 = await image.recognizeText({ * regions: [{ x: 100, y: 100, width: 200, height: 200 }] * }); * ``` */ recognizeText(options?: RecognizeTextOptions | null): Promise> /** * 在图片中查找指定文字(异步) * * 使用 PP-OCRv5 模型识别文字,并返回匹配文字的位置信息 * * # Arguments * * * `text` - 要查找的文字 * * `options` - 查找选项(可选),可指定查找区域以提升速度 * * # Example * * ```javascript * const image = await ImageData.fromFile('screenshot.png'); * const result = await image.findText('确定'); * if (result) { * console.log(`Found at: (${result.x}, ${result.y})`); * } * * // 在指定区域中查找 * const result2 = await image.findText('确定', { * regions: [{ x: 100, y: 100, width: 200, height: 200 }] * }); * ``` */ findText(text: string, options?: FindTextOptions | null): Promise /** * 转换为灰度图(异步) * * 使用标准的加权平均算法:Gray = 0.299*R + 0.587*G + 0.114*B * * # Example * * ```javascript * const image = await ImageData.fromFile('color.png'); * const grayImage = await image.grayscale(); * await grayImage.toFile('gray.png'); * ``` */ grayscale(): Promise /** * 保存图片到文件(异步) * * 根据文件扩展名自动识别格式(.png, .jpg, .jpeg, .bmp) * * # Arguments * * * `file_path` - 目标文件路径 * * # Example * * ```javascript * const image = await ImageData.fromFile('input.png'); * const resized = await image.resize(800, 600); * await resized.toFile('output.jpg'); * ``` */ toFile(filePath: string): Promise } /** Monitor 类 - 封装 XCap 的 Monitor 对象 */ export declare class Monitor { /** 获取所有显示器 */ static all(): Array /** 获取显示器 ID */ id(): number /** 获取显示器名称 */ name(): string /** 获取显示器 X 坐标 */ x(): number /** 获取显示器 Y 坐标 */ y(): number /** 获取显示器宽度 */ width(): number /** 获取显示器高度 */ height(): number /** 检查是否为主显示器 */ isPrimary(): boolean /** 获取缩放因子 */ scaleFactor(): number /** 转为 JSON 可序列化对象,便于 JSON.stringify(monitor.toJSON()) 输出 */ toJSON(): MonitorToJson /** * 截取显示器截图(异步方法) * 使用 block_in_place 避免 spawn_blocking 的线程池调度开销,提升单次截屏速度 * @param options 可选,其中 size 指定时会将截取到的图像缩放到 width x height */ captureImage(options?: CaptureImageOptions | null): Promise /** * 在显示器截图中查找图标(异步) * * 首先截取显示器图像,然后在图像中查找模板图标 * * # Example * * ```javascript * const { Monitor, ImageData } = require('rust-rpa'); * const monitors = Monitor.all(); * const template = await ImageData.fromFile('button.png'); * const result = await monitors[0].findIcon(template); * if (result) { * console.log(`Found at: (${result.x}, ${result.y})`); * } * ``` */ findIcon(template: ImageData, options?: MonitorMatchOptions | undefined | null): Promise /** * 识别显示器截图中的文字(异步) * * 首先截取显示器图像,然后识别文字 * * # Example * * ```javascript * const { Monitor } = require('rust-rpa'); * const monitors = Monitor.all(); * const results = await monitors[0].recognizeText(); * for (const result of results) { * console.log(`Text: ${result.text}, Position: (${result.x}, ${result.y})`); * } * ``` */ recognizeText(options?: MonitorRecognizeTextOptions | null): Promise> /** * 在显示器截图中查找指定文字(异步) * * 首先截取显示器图像,然后查找文字 * * # Arguments * * * `text` - 要查找的文字 * * `options` - 查找选项(可选),可指定查找区域以提升速度 * * # Example * * ```javascript * const { Monitor } = require('rust-rpa'); * const monitors = Monitor.all(); * const result = await monitors[0].findText('确定'); * if (result) { * console.log(`Found at: (${result.x}, ${result.y})`); * } * * // 在指定区域中查找 * const result2 = await monitors[0].findText('确定', { * regions: [{ x: 100, y: 100, width: 200, height: 200 }] * }); * ``` */ findText(text: string, options?: MonitorFindTextOptions | null): Promise /** * 等待指定文字出现(异步) * * 轮询查找文字,直到找到或超时 * * # Arguments * * * `text` - 要等待的文字 * * `options` - 等待选项(可选),可指定查找区域和超时时间 * * # Returns * * 返回 Promise,找到返回结果 * * # Errors * * 超时未找到则抛出错误 * * # Example * * ```javascript * const { Monitor } = require('rust-rpa'); * const monitors = Monitor.all(); * * // 等待文字出现,默认超时 3 秒 * const result = await monitors[0].waitText('确定'); * console.log(`Found at: (${result.x}, ${result.y})`); * * // 指定区域和超时时间 * const result2 = await monitors[0].waitText('确定', { * regions: [{ x: 100, y: 100, width: 200, height: 200 }], * timeout: 5000 * }); * ``` */ waitText(text: string, options?: MonitorWaitOptions | null): Promise /** * 等待指定图标出现(异步) * * 轮询查找图标,直到找到或超时 * * # Arguments * * * `template` - 要查找的图标模板 * * `options` - 等待选项(可选),可指定查找区域和超时时间 * * # Returns * * 返回 Promise,找到返回结果(found 为 true) * * # Errors * * 超时未找到则抛出错误 * * # Example * * ```javascript * const { Monitor, ImageData } = require('rust-rpa'); * const monitors = Monitor.all(); * const template = await ImageData.fromFile('button.png'); * * // 等待图标出现,默认超时 3 秒 * const result = await monitors[0].waitIcon(template); * console.log(`Found at: (${result.x}, ${result.y})`); * * // 指定区域和超时时间 * const result2 = await monitors[0].waitIcon(template, { * regions: [{ x: 100, y: 100, width: 200, height: 200 }], * timeout: 5000 * }); * ``` */ waitIcon(template: ImageData, options?: MonitorWaitOptions | null): Promise /** * 点击指定文字(异步) * * 首先使用 waitText 获取文字位置,然后点击文字中心点 * * # Arguments * * * `text` - 要点击的文字 * * `options` - 等待选项(可选),可指定查找区域和超时时间 * * # Example * * ```javascript * const { Monitor } = require('rust-rpa'); * const monitors = Monitor.all(); * * // 点击文字,默认超时 3 秒 * const clickResult = await monitors[0].clickText('确定'); * * // 指定区域和超时时间 * const result2 = await monitors[0].clickText('确定', { * regions: [{ x: 100, y: 100, width: 200, height: 200 }], * timeout: 5000 * }); * ``` */ clickText(text: string, options?: MonitorWaitOptions | null): Promise /** * 点击指定图标(异步) * * 首先使用 waitIcon 找到图标区域,然后点击图标中心点 * * # Arguments * * * `template` - 要点击的图标模板 * * `options` - 等待选项(可选),可指定查找区域和超时时间 * * # Example * * ```javascript * const { Monitor, ImageData } = require('rust-rpa'); * const monitors = Monitor.all(); * const template = await ImageData.fromFile('button.png'); * * // 点击图标,默认超时 3 秒 * const clickResult = await monitors[0].clickIcon(template); * * // 指定区域和超时时间 * const result2 = await monitors[0].clickIcon(template, { * regions: [{ x: 100, y: 100, width: 200, height: 200 }], * timeout: 5000 * }); * ``` */ clickIcon(template: ImageData, options?: MonitorWaitOptions | null): Promise } /** * Window 类 - 封装 XCap 的 Window 对象 * * 这个类直接包装了 XCap 的窗口对象,可以直接调用截图方法 */ export declare class Window { /** * 获取所有窗口对象列表(XCap Window 对象) * * 这个方法返回 XCap 的原生 Window 对象,可以直接调用 captureImage() 方法 * 注意:XCap 的窗口列表可能不完整,只包含可截图的窗口 * * # Example * * ```javascript * const { Window } = require('rust-rpa'); * * const windows = Window.all(); * console.log(`Found ${windows.length} capturable windows`); * * // 找到目标窗口并截图 * const targetWindow = windows.find(w => w.appName().includes('Chrome')); * if (targetWindow) { * const image = await targetWindow.captureImage(); * const pngBuffer = await image.toPng(); * fs.writeFileSync('screenshot.png', pngBuffer); * } * ``` */ static all(): Array /** 获取窗口 ID */ id(): number /** 获取窗口进程 ID */ pid(): number /** 获取窗口所属进程的父进程 ID */ parentId(): number /** 获取窗口应用名称 */ appName(): string /** 获取窗口标题 */ title(): string /** 获取窗口 X 坐标 */ x(): number /** 获取窗口 Y 坐标 */ y(): number /** 获取窗口宽度 */ width(): number /** 获取窗口高度 */ height(): number /** * 获取窗口尺寸(宽度和高度) * * 返回只包含尺寸信息的对象 { width: number, height: number } * * # Returns * * 返回 WindowSize 对象 { width: number, height: number } * * # Example * * ```javascript * const { Window } = require('rust-rpa'); * * const windows = Window.all(); * const window = windows[0]; * const size = window.getSize(); * console.log(`Window size: ${size.width}x${size.height}`); * ``` */ getSize(): WindowSize /** 检查窗口是否最小化 */ isMinimized(): boolean /** 检查窗口是否最大化 */ isMaximized(): boolean /** 检查窗口是否获得焦点 */ isFocused(): boolean /** 将窗口置于最前(激活并置顶) */ bringToFront(): Promise /** 最大化窗口 */ maximize(): Promise /** 最小化窗口 */ minimize(): Promise /** 转为 JSON 可序列化对象,便于 JSON.stringify(window.toJSON()) 输出 */ toJSON(): WindowToJson /** * 获取窗口所在的显示器 * * # Returns * * 返回 Monitor 对象,包含显示器信息 * * # Example * * ```javascript * const { Window } = require('rust-rpa'); * * const windows = Window.all(); * const window = windows[0]; * const monitor = window.currentMonitor(); * console.log(`Window is on monitor: ${monitor.name()}`); * console.log(`Monitor size: ${monitor.width()}x${monitor.height()}`); * ``` */ currentMonitor(): Monitor /** * 获取窗口所在显示器的 ID * * 使用 XCap 直接获取窗口所在显示器的 ID,比 currentMonitor() 更轻量 * * # Returns * * 返回显示器 ID (number) * * # Example * * ```javascript * const { Window } = require('rust-rpa'); * * const windows = Window.all(); * const window = windows[0]; * const monitorId = window.currentMonitorId(); * console.log(`Window is on monitor ID: ${monitorId}`); * ``` */ currentMonitorId(): number /** * 捕获窗口截图(异步方法) * * # Returns * * 返回 Promise * * # Errors * * - 窗口最小化时返回错误 * - 窗口不存在时返回错误 * - 截图失败时返回错误 * * # Example * * ```javascript * const { Window } = require('rust-rpa'); * const fs = require('fs'); * * async function captureWindow() { * const windows = Window.all(); * const targetWindow = windows.find(w => w.appName().includes('Chrome')); * * if (targetWindow) { * const image = await targetWindow.captureImage(); * const pngBuffer = await image.toPng(); * fs.writeFileSync('screenshot.png', pngBuffer); * } * } * * captureWindow(); * ``` * 使用 block_in_place 避免 spawn_blocking 的线程池调度开销,提升单次截屏速度 * @param options 可选,其中 size 指定时会将截取到的图像缩放到 width x height */ captureImage(options?: CaptureImageOptions | null): Promise /** * 获取窗口边界(位置和大小) * * # Returns * * 返回对象 { x: number, y: number, width: number, height: number } * * # Example * * ```javascript * const { Window } = require('rust-rpa'); * * const windows = Window.all(); * const window = windows[0]; * const bounds = window.getBounds(); * console.log(`Window at (${bounds.x}, ${bounds.y}), size: ${bounds.width}x${bounds.height}`); * ``` */ getBounds(): WindowBounds /** * 设置窗口边界(位置和大小) * * # Arguments * * * `bounds` - 窗口边界对象 { x: number, y: number, width: number, height: number } * * # Example * * ```javascript * const { Window } = require('rust-rpa'); * * const windows = Window.all(); * const window = windows[0]; * await window.setBounds({ x: 100, y: 100, width: 800, height: 600 }); * ``` */ setBounds(bounds: WindowBounds): Promise /** * 在窗口中查找图标(异步) * * 首先截取窗口图像(使用 autoSize=true),然后在图像中查找模板图标 * * # Arguments * * * `template` - 模板图标 * * `options` - 匹配选项(可选) * * # Returns * * 返回 Promise,找到返回结果,未找到返回 null * * # Example * * ```javascript * const { Window, ImageData } = require('rust-rpa'); * * const windows = Window.all(); * const window = windows.find(w => w.appName().includes('Chrome')); * const template = await ImageData.fromFile('button.png'); * const result = await window.findIcon(template); * if (result) { * console.log(`Found at: (${result.x}, ${result.y})`); * } * ``` */ findIcon(template: ImageData, options?: WindowMatchOptions | undefined | null): Promise /** * 识别窗口中的文字(异步) * * 首先截取窗口图像(使用 autoSize=true),然后识别文字 * * # Returns * * 返回 Promise,包含所有识别到的文字及其位置信息 * * # Example * * ```javascript * const { Window } = require('rust-rpa'); * * const windows = Window.all(); * const window = windows.find(w => w.appName().includes('Chrome')); * const results = await window.recognizeText(); * for (const result of results) { * console.log(`Text: ${result.text}, Position: (${result.x}, ${result.y})`); * } * ``` */ recognizeText(options?: WindowRecognizeTextOptions | null): Promise> /** * 在窗口中查找指定文字(异步) * * 首先截取窗口图像(使用 autoSize=true),然后查找文字 * * # Arguments * * * `text` - 要查找的文字 * * `options` - 查找选项(可选),可指定查找区域以提升速度 * * # Returns * * 返回 Promise,找到返回结果,未找到返回 null * * # Example * * ```javascript * const { Window } = require('rust-rpa'); * * const windows = Window.all(); * const window = windows.find(w => w.appName().includes('Chrome')); * const result = await window.findText('确定'); * if (result) { * console.log(`Found at: (${result.x}, ${result.y})`); * } * * // 在指定区域中查找 * const result2 = await window.findText('确定', { * regions: [{ x: 100, y: 100, width: 200, height: 200 }] * }); * ``` */ findText(text: string, options?: WindowFindTextOptions | null): Promise /** * 等待指定文字出现(异步) * * 轮询查找文字,直到找到或超时 * * # Arguments * * * `text` - 要等待的文字 * * `options` - 等待选项(可选),可指定查找区域和超时时间 * * # Returns * * 返回 Promise,找到返回结果 * * # Errors * * 超时未找到则抛出错误 * * # Example * * ```javascript * const { Window } = require('rust-rpa'); * const windows = Window.all(); * const window = windows.find(w => w.appName().includes('Chrome')); * * // 等待文字出现,默认超时 3 秒 * const result = await window.waitText('确定'); * console.log(`Found at: (${result.x}, ${result.y})`); * * // 指定区域和超时时间 * const result2 = await window.waitText('确定', { * regions: [{ x: 100, y: 100, width: 200, height: 200 }], * timeout: 5000 * }); * ``` */ waitText(text: string, options?: WindowWaitOptions | null): Promise /** * 等待指定图标出现(异步) * * 轮询查找图标,直到找到或超时 * * # Arguments * * * `template` - 要查找的图标模板 * * `options` - 等待选项(可选),可指定查找区域和超时时间 * * # Returns * * 返回 Promise,找到返回结果(found 为 true) * * # Errors * * 超时未找到则抛出错误 * * # Example * * ```javascript * const { Window, ImageData } = require('rust-rpa'); * const windows = Window.all(); * const window = windows.find(w => w.appName().includes('Chrome')); * const template = await ImageData.fromFile('button.png'); * * // 等待图标出现,默认超时 3 秒 * const result = await window.waitIcon(template); * console.log(`Found at: (${result.x}, ${result.y})`); * * // 指定区域和超时时间 * const result2 = await window.waitIcon(template, { * regions: [{ x: 100, y: 100, width: 200, height: 200 }], * timeout: 5000 * }); * ``` */ waitIcon(template: ImageData, options?: WindowWaitOptions | null): Promise /** * 点击指定文字(异步) * * 首先使用 waitText 获取文字位置,然后点击文字中心点 * * # Arguments * * * `text` - 要点击的文字 * * `options` - 等待选项(可选),可指定查找区域和超时时间 * * # Example * * ```javascript * const { Window } = require('rust-rpa'); * const windows = Window.all(); * const window = windows.find(w => w.appName().includes('Chrome')); * * // 点击文字,默认超时 3 秒 * const clickResult = await window.clickText('确定'); * * // 指定区域和超时时间 * const result2 = await window.clickText('确定', { * regions: [{ x: 100, y: 100, width: 200, height: 200 }], * timeout: 5000 * }); * ``` */ clickText(text: string, options?: WindowWaitOptions | null): Promise /** * 点击指定图标(异步) * * 首先使用 waitIcon 找到图标区域,然后点击图标中心点 * * # Arguments * * * `template` - 要点击的图标模板 * * `options` - 等待选项(可选),可指定查找区域和超时时间 * * # Example * * ```javascript * const { Window, ImageData } = require('rust-rpa'); * const windows = Window.all(); * const window = windows.find(w => w.appName().includes('Chrome')); * const template = await ImageData.fromFile('button.png'); * * // 点击图标,默认超时 3 秒 * const clickResult = await window.clickIcon(template); * * // 指定区域和超时时间 * const result2 = await window.clickIcon(template, { * regions: [{ x: 100, y: 100, width: 200, height: 200 }], * timeout: 5000 * }); * ``` */ clickIcon(template: ImageData, options?: WindowWaitOptions | null): Promise /** * 监听窗口内容变化,当检测到变化时触发回调函数 * * 底层使用降采样差异检测;启动后首帧仅建立对比基线、**不**调用 callback, * 之后仅在相对上一帧检测到变化时才触发回调,资源开销远低于定时轮询截图。 * * @param options 监听选项(可选) * @param callback 检测到相对上一帧有变化时的回调;参数 `changeRatio` 为降采样帧上估算的像素变化比例(约 0–1) * @returns WindowWatcher 句柄,调用 stop() 可停止监听 * * @example * ```javascript * // 场景 1:监听窗口变化 * const watcher = targetWindow.watchChanges( * { threshold: 0.02, from: 'window' }, * (info) => { * console.log('窗口内容发生了变化', info.changeRatio, info.changedPixels); * } * ); * ``` * * @example * ```javascript * // 场景 2:仅监听窗口内多个区域 * const watcher = targetWindow.watchChanges( * { * regions: [ * { x: 100, y: 200, width: 400, height: 300 }, * { x: 0, y: 0, width: 200, height: 80 }, * ], * }, * (info) => { * console.log('指定区域内容发生了变化', info.changeRatio, info.changedPixels); * } * ); * ``` * * @example * ```javascript * // 场景 3:提高阈值减少微小变化触发 * const watcher = targetWindow.watchChanges( * { threshold: 0.02 }, * (info) => { * console.log('窗口内容发生持久变化', info.changeRatio); * } * ); * watcher.changeOptions({ threshold: 0.05 }); * ``` */ watchChanges( options: WindowWatchOptionsJs | null | undefined, callback: WindowChangeCallback ): WindowWatcher } /** Clipboard 类 - 剪贴板控制 */ export declare class Clipboard { /** 读取剪贴板文本内容 */ static readText(): Promise /** 将文本写入剪贴板 */ static writeText(text: string): Promise /** * 将图片写入剪贴板 * * 支持三种输入方式: * - 文件路径(string):如 '/path/to/image.png' * - base64 字符串(string):如 'data:image/png;base64,...' 或纯 base64 编码 * - Buffer:PNG/JPEG/BMP 等编码后的图片二进制数据 * * 自动解码获取宽高,无需手动传入 */ static writeImage(source: string | Buffer): Promise /** 将文件路径写入剪贴板,粘贴时可在资源管理器/访达中粘贴文件。可传单个路径或路径数组 */ static writeFile(paths: string | string[]): Promise /** 执行粘贴操作(使用 Cmd/Ctrl+V 快捷键) */ static paste(): Promise /** * 将文本写入剪贴板并粘贴,完成后自动恢复剪贴板原始内容 * * @param text 要粘贴的文本 */ static pasteText(text: string): Promise /** * 将图片写入剪贴板并粘贴,完成后自动恢复剪贴板原始内容 * * source 支持文件路径(string)、base64 / data URI(string)或 Buffer */ static pasteImage(source: string | Buffer): Promise /** * 将文件路径写入剪贴板并粘贴,不会自动恢复剪贴板原始内容 * * @param paths 单个文件路径或路径数组 */ static pasteFile(paths: string | string[]): Promise } /** * 权限检查工具类 * * - macOS:检查辅助功能和屏幕录制权限,无权限时可自动弹出系统授权对话框 * - Windows:检查是否以管理员身份运行 */ export declare class Permission { /** * 检查辅助功能权限(鼠标、键盘、窗口操作等需要此权限) * * - macOS:调用系统 API 检查,prompt=true(默认)时无权限会弹出授权对话框 * - Windows:检查是否以管理员身份运行 * * @param prompt 无权限时是否弹出授权对话框(仅 macOS 生效),默认 true * @returns 是否已拥有权限 */ static checkAccessibility(prompt?: boolean | null): boolean /** * 检查屏幕录制权限(截图功能需要此权限) * * - macOS:调用系统 API 检查,prompt=true(默认)时无权限会弹出授权对话框 * - Windows:检查是否以管理员身份运行 * * @param prompt 无权限时是否弹出授权对话框(仅 macOS 生效),默认 true * @returns 是否已拥有权限 */ static checkScreenCapture(prompt?: boolean | null): boolean } /** * 暂停/等待指定时间 * @param ms - 等待时间(毫秒) * @returns Promise * @example * await pause(1000); // 等待 1 秒 */ export declare function pause(ms: number): Promise