Global

Methods

ensureBins(optopt) → {Promise}

Description:
  • 取得本套件之外部執行檔(AutoHotkey64.exe、z*.ahk腳本、screenCapture_*.exe): 首次使用時下載(或自鏡像取得)並以bin/manifest.json之SHA-256與大小校驗, 之後自快取取得(亦校驗)

    規格: 外部執行檔之存放下載校驗與離線(制式規格)§6; 實作為wsemi之fsEnsureBins, 本套件不另寫下載、快取、鏡像、校驗 環境變數: W_BIN_CACHE(共用快取資料夾)、W_BIN_MIRROR(鏡像, 本地資料夾或http(s)網址)、W_BIN_OFFLINE(1為離線), 見README〈外部執行檔〉

Source:
Example
import ensureBins from 'w-mousekey/src/ensureBins.mjs'

let bins = await ensureBins({ names: ['AutoHotkey64.exe', 'zclick.ahk'] })
console.log(bins['AutoHotkey64.exe'])
Parameters:
Name Type Attributes Default Description
opt Object <optional>
{}

輸入設定物件, 交wsemi之fsEnsureBins(names、cacheDir、mirror、offline、onProgress等), pkgRoot固定為本套件根

Returns:

回傳Promise, resolve回傳{ [檔名]: 絕對路徑 }, reject回傳帶code之Error(E_OFFLINE_MISSING等)

Type
Promise

init(opt)

Source:
Parameters:
Name Type Description
opt Object
Properties
Name Type Description
moukey function

async (action, args) => void action: 'click' | 'drag' | 'scroll' | 'sendChar' | 'sendString' | 'sendCombo' args: 依action而定 click: [x, y, btn?, count?] btn: 'left'|'right'|'middle' (default 'left'), count: int (default 1) drag: [x1, y1, x2, y2, btn?] btn: 同click (default 'left') scroll: [x, y, dir, amount?] dir: 'up'|'down'|'left'|'right', amount: int (default 3) sendChar: [char] 純文字單字元 (SendText) sendString: [str] 純文字字串 (SendText) sendCombo: [combo] xdotool風格組合鍵字串 (如 'ctrl+v', 'F5')

init(opt)

Source:
Parameters:
Name Type Description
opt Object
Properties
Name Type Description
screenshot function

async () => Buffer(png), 回傳整個畫面的PNG Buffer

(async) runScp(inputFile, optopt) → {Promise}

Description:
  • 讀取腳本檔並依序執行滑鼠點擊步驟

    腳本檔為JSON5,內容為單一腳本物件或腳本物件陣列,腳本物件含repeat(重複次數,整數,負數為無限重複,預設1)、delay(每次重複完成後等待毫秒數,非負整數,預設0)與steps(步驟陣列),步驟含x、y(螢幕座標,須為整數,否則拋錯)與delay(點擊後等待毫秒數,整數,預設0)

Source:
Parameters:
Name Type Attributes Default Description
inputFile String

輸入腳本檔路徑

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
onTrace function <optional>
null

輸入觀察回調函數,於內部事件發生當下同步呼叫,傳入一個凍結之事件物件{ type, ... },供測試以事件(而非等待時間)同步與診斷;sp為腳本物件序號、rp為重複次序、step為步驟序號,皆從1起算;type為'empty'時為腳本無內容而即將返回,'start'時為即將開始執行(含nSp為腳本物件數量),'step'時為即將點擊(含sp、rp、step、x、y),'stepWait'時為點擊後即將等待步驟延遲(含sp、rp、step、ms,僅ms大於0時),'repeatWait'時為該次重複之步驟皆完成而即將等待重複延遲(含sp、rp、ms,僅ms大於0時),'repeat'時為該次重複(含其延遲)完成(含sp、rp),'error'時為步驟拋錯而即將向外拋出(含sp、rp、step),'finish'時為全部執行完畢而即將返回;回調不帶接收者呼叫,其拋錯與回傳值皆忽略,不影響執行與結果,預設null

Returns:

回傳Promise,resolve代表執行完畢(repeat為負數時永不resolve)

Type
Promise

(async) waitPics(names, optopt) → {Promise}

Description:
  • 輪詢螢幕直到辨識到指定圖片(withClick時一併點擊),多張圖時任一張辨識成功即結束

    每輪依序以ckPic辨識names內各圖,任一成功即結束並回傳true,皆失敗則等待timeDelay後進入下一輪,嘗試完numMax輪仍皆失敗才回傳false;其餘opt同ckPic(fdTar、fdTmp、x、y、width、height、threshold、modeCompare、withClick、withDrag、dx、dy等),辨識所需之圖檔或資料夾不存在時ckPic拋錯,錯誤原樣向外拋出

Source:
Parameters:
Name Type Attributes Default Description
names String | Array

輸入圖檔名稱(不含副檔名,檔案為{fdTar}/{name}.png)字串或字串陣列

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
numMax Integer <optional>
60

輸入最大輪數,預設60

timeDelay Integer <optional>
1500

輸入每輪皆失敗後之等待毫秒數,預設1500

onTrace function <optional>
null

輸入觀察回調函數,於內部事件發生當下同步呼叫,傳入一個凍結之事件物件{ type, ... },供測試以事件(而非等待時間)同步與診斷;type為'round'時為即將進行第i輪(含i為輪次從1起算、numMax為最大輪數),'check'時為ckPic已完成一張圖之辨識(含i、name為圖檔名稱、ok為是否辨識成功),'wait'時為該輪皆失敗而即將等待(含i、timeDelay為opt.timeDelay之值),'found'時為辨識成功而即將回傳true(含i、name),'giveUp'時為全部輪數皆失敗而即將回傳false(含numMax),'error'時為ckPic拋錯而即將向外拋出(含i、name);回調不帶接收者呼叫,其拋錯與回傳值皆忽略,不影響輪詢與結果,預設null

Returns:

回傳Promise,resolve回傳布林,true代表有一張圖辨識成功,false代表嘗試完全部輪數皆失敗

Type
Promise