[設計參考] 小算盤操作程式碼參考

以下圖片檔名請自行替換

let crops = {
  "num1" : "crop-b972bcc13a070f1c6b48c70c433c52a0364b922f447c85ff05f7ea72e6a5a87d.png",
  "num2" : "crop-b95187d18a4145e31f99e8fa5377a09867bdbd3606dc99bc8430d252137dc150.png",
  "num3" : "crop-a51f4bedb996c4b835b9385169b1c69644831aaa60bf598d0c9e8e11fc0274cf.png",
  "add" : "crop-65f5ceb14b71924cdbb8b34731c17f938f879a27ad7f3be4b9bd09fcb6b2de46.png",
  "multiply" : "crop-fa51b35a14d727e79e5b1f936abdaf48e25631634af2e523542dffe3e4e5b668.png",
  "equal" : "crop-f5bef78753d3b4dbca43f75f4ac792ba46819c6a8af693fb90313ccb527d1856.png",
  "history" : "crop-c9a78184a476514245b082e61d9a953a28c14e4bb962c6d27b2446d232dcbbbb.png"
}

async function clickNum(num){
  for(let i = 0; i<num.length; i++){
    if(num[i] == "1") await api.clickCrop(crops["num1"], 54, 40)
    if(num[i] == "2") await api.clickCrop(crops["num2"], 54, 40)
    if(num[i] == "3") await api.clickCrop(crops["num3"], 54, 40)
  }
}
async function clickOperator(op){
  if(op == "add") await api.clickCrop(crops["add"], 54, 40)
  if(op == "multiply") await api.clickCrop(crops["multiply"], 54, 40)
  if(op == "equal") await api.clickCrop(crops["equal"], 54, 40)
}
// create csv file
await api.writeCSV('table.csv', [{'num1' : 11, 'operator' : "add", "num2" : 13}, {'num1' : 2, 'operator' : "multiply", "num2" : 31}])
// open calc
await api.shell.openPath('C:\\Windows\\System32\\calc.exe')

//read csv
let data = await api.readCSV('table.csv', ',', 0)
console.log(data)
//according to table.csv 
let gate = await api.screen.waitFor(crops["num1"], 10000)
console.log(gate)
if(gate){
  for(let i = 0; i<data.length; i++){
    //click first num
    await clickNum(data[i]["num1"])
    //click opertator
    await clickOperator(data[i]["operator"])
    //click second num
    await clickNum(data[i]["num2"])
    //click equal
    await clickOperator("equal")
    //copy result
      //move to result
    await api.moveToCrop(crops["history"], 25, 135);
      //drag 
    await api.mouse.drag(384, 397)
      //ctrl + C
    await api.ctrlC()
    await api.sleep(1000)
      //read clipboard
    let result = api.clipboard.readText()
    data[i]['result'] = result
    console.log(data)
  }
  //write csv
  await api.writeCSV('result.csv', data)
}