[觸動精靈]觸動精靈官方手冊流水帳1

官方手冊android

http://www.touchsprite.com/helpdoc#/doc?id=2148c#


小知識:手冊的查詢功能瀏覽器

image

注意 這裏能精確的查詢對應函數 可是沒法模糊查詢 好比記不起某個函數名 可是記得函數的說明的幾個關鍵字  這樣的模糊查詢並不支持 服務器


觸動精靈的lua版本是5.2.3網絡

traceprint("lua版本:[" .. tostring(_VERSION) .. "]")--  [init.lua]第10行  lua版本:[Lua 5.2]app


觸動精靈的編碼是UTF8  一旦運行期間出現亂碼 極可能是編碼不對的問題異步


遍歷表的時候順手寫了一個顯示任何類型變量的類型 值   的函數編輯器

--[[功能:輸出變量類型值 包含遍歷表 包括嵌套表 --參數 第一個參數能夠是任何類型變量 若是是table 第二個參數是設置表元素的間隔符的 也能夠不寫 --]]
function showInfo(t, tab) return try{ function () --下面代碼隨便寫 有可能拋出異常便可 
            local str = str or ""
            --print(type(t))
            --if not t then
            if type(t)~="table" then                
                --error("table is nil")
                return type(t) .. ":"  .. tostring(t) end tab = tab or "  " tab = tab .. "  " str = str .. "{\n"

            if type(t) == "table" then
                for k, v in pairs(t) do
                    if type(k) == "number" then str = str .. string.sub(tab, 2, string.len(tab)) .. "[" .. tostring(k) .. "]" .. " = "
                    else str = str .. string.sub(tab, 2, string.len(tab)) .. "[\"" .. tostring(k) .. "\"]" .. " = "
                    end
                    if type(v) == "string" then str = str .. "\"" .. v .. "\"" .. "\n"
                    elseif type(v) == "number" then str = str .. tostring(v) .. "\n"
                    elseif type(v) == "boolean" then str = str .. tostring(v) .. "\n"
                    elseif type(v) == "function" then str = str .. tostring(v) .. "\n"
                    elseif type(v) == "thread" then str = str .. "thread : " .. tostring(v) .. "\n"
                    elseif type(v) == "userdata" then str = str .. "userdata : " .. tostring(v) .. "\n"
                    elseif type(v) == "table" then str = str .. showInfo(v, tab) .. "\n"
                    else str = str .. "unknow : " .. tostring(v) .. "\n"
                    end
                end str = str .. string.sub(tab, 2, string.len(tab) - 1) .. "}"
            else str = t end
            return str end, catch{ function (errors) --這裏對應函數名要改
                local tempStr="" tempStr="函數[" .. tostring("traversalTable") .. "] 錯誤信息:".. tostring(errors) traceprint(tempStr) dialog(tempStr, 3) end } } end


越獄及 root 常識 的確頗有用ide

http://www.touchsprite.com/docs/5383函數


觸動的三款軟件的優劣

image

三個軟件均可以實現咱們的腳本功能 

小精靈 免費的不支持網絡插件和高級擴展庫 放棄小精靈   收費的每個月5.5/臺

觸動企業版  收費很貴 按天收費 依然不考慮

觸動精靈app  安卓免費 IOS收費 把腳本上傳到手機上直接運行就好 或者生成二維碼讓手機掃碼  問題是源碼也有暴露的危險  暴露源碼 可是能夠對源碼加密tsp文件 只能推薦這個

image


三個軟件在功能上區別

觸動專業版在批量控制就是中控上官方已經提供了這服務 其餘2個沒有

小精靈免費版沒網絡函數和高級擴展庫 很難受

仍是那個結論  依然是用觸動精靈app來運行腳本


觸動精靈 Android 使用手冊(推薦仔細看看 不少使用細節)

http://www.touchsprite.com/docs/4928 

安裝觸動app

觸動app的帳號登陸 由於運行tsp腳本必須登陸 lua腳本不用

找腳本  觸動腳本市場的下載和使用

觸動app端寫腳本 觸動app左上點開 新建腳本

觸動app錄製腳本

tsp腳本的生成和上傳      開發者平臺--新建腳本---- 上傳工程壓縮包  記住腳本id ----在觸動app的右上第一個按鈕寫入腳本id 下載便可

更新腳本tsp  不過仍是推薦刪除再從新下載腳本  就是按鍵下的自動更新腳本

激活腳本  收費腳本纔會遇到

定時腳本和開機啓動腳本

受權相關

觸動app 插件 設備信息 日誌位置等等


觸動精靈 IOS使用手冊

http://www.touchsprite.com/docs/4875


統計某個區域的指定顏色數量:看到getColor函數   獲取某個座標的顏色數值 想起按鍵有個統計某個區域的指定顏色數量 這個函數仍是頗有用的 順手寫了 不過從效率上看很通常 統計半個屏幕的符合的顏色數量大約1-2秒  有點慢 目前就用這個湊合把

--[[ 獲取必定區域內 和指定顏色類似的顏色點的數量 sim注意按照觸動的習慣來把 80 90 而不是0.8 .09 colorStr 是十六進制的顏色數值 不過也能夠是顏色字符串 getColorNum(5,164,347,479,0x00b98c,9 --]]
function getColorNum(x1,y1,x2,y2,colorStr,sim) return try{ function () --下面代碼隨便寫 有可能拋出異常便可
            local result=0
            local tempColor local tempPercent keepScreen(true); for y=y1,y2 do
                for x=x1,x2 do tempColor=getColor(x, y) if tempColor>=tonumber(colorStr) then tempPercent=tonumber(colorStr)/tempColor else tempPercent=tempColor/tonumber(colorStr) end
                    if tempPercent*100>tonumber(sim) then result=result+1
                    end    
                    --mSleep(1)
                end                
            end keepScreen(false); return result end, catch{ function (errors) --這裏對應函數名要改
                local tempStr="" tempStr="函數[" .. tostring("getColorNum") .. "] 錯誤信息:".. tostring(errors) traceprint(tempStr) dialog(tempStr, 3) end } } end


發現我本身封裝的traceprint 顯示當前文件名和行號 在實際發佈位TSP文件後 發現debug庫就無效了 那麼輸出當前文件名和行號也是空了

若是變成了TSP文件 那麼就不顯示文件名和行號了 由於沒法獲取到了 traceprint也要變更一下

config={} ----日誌相關(暫時不考慮多日誌並存的狀況)
config["isLog"]=true--是否開啓日誌輸出和日誌文件
config["logFileName"]=tostring(config["scriptName"]) .. tostring(os.date("%Y%m%d%H%M%S",os.time())) --只是當前日誌文件名字不是完整路徑年月日時分秒 如XXXX20190816112336 加了個前綴
config["logMode"]=0--0表示寫入本地日誌文件--1 - 生成 1 個以時間戳命名的後綴爲 .log 的文件到 log 文件夾下 2 - 異步發送到服務器(支持引擎 v1.7.0 及 Android v2.4.1 以上版本)3 - 同步發送到服務器(僅支持觸動精靈 iOS v1.7.0 及以上版本) -----是否開啓日誌行號和文件名顯示(不須要設置) 注意 這個只是再調試狀態下才能出現 正式腳本下debug庫是無效的 若是debug庫裏面的文件名裏面沒找到.lua 天然當前debug庫是無效的 那麼日誌輸出就不要帶行號和文件名
config["isAddLineAndFilename"]=(string.find(tostring(debug.getinfo(1).source),".lua") and {true} or {false})[1] --輸出日誌信息到日誌窗口和日誌文件 日誌文件的輸出還有是否有行號和文件名由配置表控制 
function traceprint(str) local info local tempStr=""
    if config["isAddLineAndFilename"] then--是否是處於調試模式
        info = debug.getinfo(2) tempStr="[" .. tostring(info["source"]) .. "]" .. "" .. tostring(info["currentline"]) .. "" .. tostring(str) else tempStr=tostring(str) end
    if config["isLog"] then wLog(config["logFileName"], tostring(tempStr)) end nLog(tempStr) mSleep(5)--爲了nLog的顯示順序的暫時解決辦法
end


截圖函數 能夠單獨截圖一張 也能夠在規定時間內連續截圖多張 截圖一次大約佔用0.4秒時間 第五個參數設置個截圖時間便可 這個時間內儘可能多的截圖  由於觸動沒有連續截圖的功能 只能用這個函數來代替

--[[ 截圖工具 picname只須要文件名便可 默認放到觸動的資源文件夾下 文件名是當前日期時間爲名 x1, y1, x2, y2 沒什麼說的 最後2個參數 都是用於短期內連續截多圖 第一個參數是限定的時間 第二個參數是在這個限定時間內截多少圖 支持 須要ts庫生成時間戳 通過實際測試 截圖函數自己須要0.4秒左右的時間消耗 因此不設置截圖幾張了 只設置截圖的限制時間就行 示例 snapshotEx(0,0,config["width"]-1,config["height"]-1)--截一圖 snapshotEx(0,0,config["width"]-1,config["height"]-1,3)--3秒內儘量多的截圖 --]]
function snapshotEx(x1, y1, x2, y2,...) local args={...} return try{ function () --下面代碼隨便寫 有可能拋出異常便可
            local result=-1
            local startTime local tempPath=userPath() .. "/res/"
            local tempTime  local tempFileName local tempTable local tempStartTime local tempDelay local tempStr="截圖結果:" .. tempPath .. " ["
            if args[1]==nil then
                --表示正常截圖便可
                tempTime=ts.ms() tempTable=strSplit(tostring(tempTime),".") tempFileName=os.date("%Y%m%d%H%M%S",time) ..tostring(tempTable[2]) .. ".png" snapshot(tempPath .. tempFileName, x1, y1, x2, y2) tempStr=tempStr .. tempFileName .. "]" traceprint(tempStr) else
                --須要連續截圖了
                if type(args[1])=="number" then
                    --args[2]=(tonumber(args[2]) and {tonumber(args[2])} or {5})[1] 
                    startTime=os.clock() --tempDelay=math.floor(tonumber(args[1])*1000/tonumber(args[2]))
                    while ((os.clock()-startTime)<args[1]) do tempTime=ts.ms() tempTable=strSplit(tostring(tempTime),".") tempFileName=os.date("%Y%m%d%H%M%S",tempTime) .. tempTable[2] .. ".png" snapshot(tempPath .. tempFileName, x1, y1, x2, y2) tempStr=tempStr .. " " .. tempFileName end tempStr=tempStr .. "]" traceprint(tempStr) else
                    --連續截圖參數不合法 就不連續截圖了 就單截圖了
                    tempTime=ts.ms() tempTable=strSplit(tostring(tempTime),".") tempFileName=os.date("%Y%m%d%H%M%S",time) .. tempTable1[2] .. ".png" snapshot(tempPath .. tempFileName, x1, y1, x2, y2) tempStr=tempStr .. tempFileName .. "]" traceprint(tempStr) end
            end
        end, catch{ function (errors) --這裏對應函數名要改
                local tempStr="" tempStr="函數[" .. tostring("snapshotEx") .. "] 錯誤信息:".. tostring(errors) traceprint(tempStr) dialog(tempStr, 3) end } } end


utf8庫的相關函數

http://www.mytju.com/classcode/tools/encode_utf8.asp  utf8編碼和字符的轉化

utf8.char(35302,21160,58,31934,28789) ===》觸動:精靈 具體對應去上面網址查詢

具體的資料沒找到多少  不過庫內的函數也不多的


tsp/p4u 是觸動/幫你玩開發者平臺在開發者上傳腳本壓縮包時將腳本在線加密生成的腳本格式


checkScriptAuth 腳本類型和受權

有點意思 能夠判斷當前腳本是什麼類型的 是加密後的tsp/p4u 仍是 lua源碼 checkScriptAuth().type

也能夠得到腳本id  checkScriptAuth().id  沒再開發者平臺生成腳本的 就沒有這個 默認-1

或者當前腳本是否受權


仔細看了一下getNetTime()函數  這個函數若是失敗返回0 這個狀況沒注意到

那麼咱們原來的判斷到期時間函數就須要額外的調整一下 加3行代碼便可 若是不加 萬一斷網狀態下 這個getNetTime函數返回0 就是1970年 認爲當前時間是1970年 那麼腳本確定不會過時了

--腳本是否過時判斷 設置過時時間在配置表的config["expireTime"]裏面設置 格式是"2019-10-02 12:30:12"或者表{2019,10,2,12,30,12} 開啓判斷是 config["isExpireTime"] =true --返回值沒有 過時了就彈出窗口而後中止腳本
function isExpireTime() return try{ function () --下面代碼隨便寫 有可能拋出異常便可 
            local result=-1
            local nowTime local expireTime nowTime=getNetTime()  if nowTime==0 then  
                error("沒法獲取到網絡時間 請檢查")
            end expireTime=dataToTimeStamp(config["expireTime"]) if nowTime>expireTime then
                --過時了 
                result=1 traceprint("腳本過時了 請檢查") dialog("腳本過時了 請檢查", 0) lua_exit() else
                --在試用期內
                result=-1 traceprint("在試用期內 到期時間[".. tostring(config["expireTime"])  .. "]") end        
            --return result
        end, catch{ function (errors) --這裏對應函數名要改
                local tempStr="" tempStr="函數[" .. tostring("isExpireTime") .. "] 錯誤信息:".. tostring(errors) traceprint(tempStr) dialog(tempStr, 3) end } } end


inputText的使用

由於觸動沒有提供相似按鍵的keypress函數 咱們要實現點擊del鍵

for i=1,15 do  --點擊15下del鍵 刪除輸入框內的內容
     inputText("\b")
     mSleep(10)
end

實現清理文本框內容鍵

--清理輸入框的內容 前提是當前光標已經處於輸入框的尾部了 --參數不寫 默認刪除15下 寫了就按照參數數量刪除
function clearInputBox(delNum) return try{ function () --下面代碼隨便寫 有可能拋出異常便可 
            delNum=tonumber(delNum) or 15--不寫就是默認刪除15下
            for i=1,delNum do inputText("\b") mSleep(10) end
        end, catch{ function (errors) --這裏對應函數名要改
                local tempStr="" tempStr="函數[" .. tostring("clearInputBox") .. "] 錯誤信息:".. tostring(errors) traceprint(tempStr) dialog(tempStr, 3) end } } end


瞭解下 

isFrontApp 判斷前臺應用    

frontAppBid 獲取前臺應用   

appBundlePath 獲取應用安裝路徑 

openURL 打開網絡地址   這個我記得按鍵的山海師插件有其餘的瀏覽器的支持 能夠去看下 紫貓插件的也有相似的功能

其實本質就是用os.execute執行系統命令 下面是山海師對應的命令源碼

function QMPlugin.OpenWeb(url)
     sh_init()
     if url:find(":") == nil then url = "http://"..url end
     os.execute(string.format("am start -a android.intent.action.VIEW -d "..url))
end


小知識 按鍵精靈下的山海師插件 爲咱們提供了不少已經寫好的lua函數  感謝山海師老師 整個插件都是開源的 有很高的參考價值


順手把 取文本中間 函數寫了下

--取先後兩個字符串之間的內容 就是易語言的取文本中間函數 --返回值 沒東西返回nil 又符合要求的返回對應字符串 --注意的是前綴後綴裏面若是夾雜着正則的元字符 須要轉義 否則獲取的結果就有誤 --還有注意處理的字符串若是出現多個前綴後綴 那麼只能取到第一個符合要求的
function getTextCenterStr(str,prefixStr,suffixStr) return try{ function () --下面代碼隨便寫 有可能拋出異常便可 
            local result=""
            local tempTable str=tostring(str)  prefixStr=tostring(prefixStr)  suffixStr=tostring(suffixStr) tempTable=string.match(str,prefixStr .. "(.-)" .. suffixStr) result=tempTable return result end, catch{ function (errors) --這裏對應函數名要改
                local tempStr="" tempStr="函數[" .. tostring("getTextCenterStr") .. "] 錯誤信息:".. tostring(errors) traceprint(tempStr) dialog(tempStr, 3) end } } end


瞭解下

getDeviceType 獲取設備類型 是真的手機 仍是模擬器 仍是蘋果

getDeviceID 獲取觸動精靈設備號   表明當前設備的惟一性

getMemoryInfo 獲取設備內存信息  主要用來判斷當前的內存佔用狀況 佔用太大則清理下內存

getTSVer、getOSVer 獲取引擎版本號、獲取系統版本號  獲取觸動版本和當前手機系統版本 由於觸動不少函數對系統版本或者觸動版本有要求

getOSType 獲取設備系統  是安卓仍是IOS



瞭解下

vibrator 手機振動

for var = 1,5 do
     vibrator();                --振動
     mSleep(1000);            --延遲 1 秒
end

播放音頻

playAudio 播放音頻  stopAudio 中止播放  播放音頻之類的 通常經常使用於提醒用戶 腳本出現了問題 或者腳本快結束了 或者其餘提醒

注意 mp3文件從編輯器上傳到手機 發送都是失敗 不明因此 只能整個工程打包上傳才能夠 不清楚是文件太大不讓單獨上傳仍是文件格式不容許上傳

--播放音樂 --參數 第一個要音頻的完整路徑 通常是在 config["userPath"] 文件夾裏面 第二個參數單位是秒 不寫默認10秒 --支持 配置表 config["systype"] 獲取是安卓仍是IOS
function playSound(videoPath,limitTime) return try{ function () --下面代碼隨便寫 有可能拋出異常便可 
            limitTime=tonumber(limitTime) or 10
            
            if fileExist(videoPath)==false then
             error("[" .. tostring(videoPath) .. "] 沒法找到對應文件 請檢查") end
            
            if config["systype"]=="android" then playAudio(videoPath); --播放 test.mp3
                mSleep(limitTime*1000) stopAudio(); --中止播放
            else playAudio(videoPath); --播放 test.mp3
                mSleep(limitTime*1000) playAudio(""); --iOS 中止播放,Android 參考 stopAudio 函數
            end
            
        end, catch{ function (errors) --這裏對應函數名要改
                local tempStr="" tempStr="函數[" .. tostring("playSound") .. "] 錯誤信息:".. tostring(errors) traceprint(tempStr) dialog(tempStr, 3) end } } end




123

相關文章
相關標籤/搜索