以前是用按鍵精靈和Sikuli寫腳本
最近開始用觸摸精靈(手機按器)
覺得超好用
分享我常用的function給大家
-- 點擊
function click(x, y)
touchDown(0, x, y)
mSleep(100)
touchUp(0)
end
----------------------------------------------------------------
--尋找圖片,含Timeout與X,Y位移
--參數說明:
-- sPicName:圖片完整路徑(只支援bmp檔),如"/mnt/sdcard/Arthur/UseItems.bmp"
-- iTimeout:幾秒內未偵測到圖片,則離開function
-- iDelayMS:發現圖片點擊後,等待多少ms (1000ms = 1秒)
-- Xmove:發現圖片後,點擊座標X軸位移量
-- Ymove:發現圖片後,點擊座標Y軸位移量
-- 回傳值:true-有發現圖片,false-未發現圖片
----------------------------------------------------------------
function FindPic(sPicName, iTimeout, iDelayMS, Xmove, Ymove)
local ifind;
local iFuncX = -1;
local iFuncY = -1;
local t= os.time();
ifind = false;
repeat
iFuncX, iFuncY = findImage(sPicName);
if iFuncX > 0 and iFuncY > 0 then
click(iFuncX+Xmove, iFuncY+Ymove);
mSleep(iDelayMS);
ifind = true;
end
until((os.difftime(os.time(), t) > iTimeout) or (iFuncX > 0))
return ifind;
end
----------------------------------------------------------------
--模糊尋找圖片,含Timeout與X,Y位移、精度
--參數說明:
-- sPicName:圖片完整路徑(只支援bmp檔),如"/mnt/sdcard/Arthur/UseItems.bmp"
-- iTimeout:幾秒內未偵測到圖片,則離開function
-- iDelayMS:發現圖片點擊後,等待多少ms (1000ms = 1秒)
-- Xmove:發現圖片後,點擊座標X軸位移量
-- Ymove:發現圖片後,點擊座標Y軸位移量
-- Similarity:精度0.1~1.0,越高表示要越符合圖片,比對才會成立
-- 回傳值:true-有發現圖片,false-未發現圖片
----------------------------------------------------------------
function FindPicFuzzy(sPicName, iTimeout, iDelayMS, Xmove, Ymove, Similarity)
local ifind;
local iFuncX = -1;
local iFuncY = -1;
local t= os.time();
ifind = false;
repeat
iFuncX, iFuncY = findImageFuzzy(sPicName, Similarity);
if iFuncX > 0 and iFuncY > 0 then
click(iFuncX+Xmove, iFuncY+Ymove);
mSleep(iDelayMS);
ifind = true;
end
until((os.difftime(os.time(), t) > iTimeout) or (iFuncX > 0))
return ifind;
end
---------------------------------------------------------------- |