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


官方手冊

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


小知識:手冊的查詢功能

image

注意 這里能精確的查詢對應函數 但是無法模糊查詢 比如記不起某個函數名 但是記得函數的說明的幾個關鍵字  這樣的模糊查詢並不支持


觸動精靈的lua版本是5.2.3

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


觸動精靈的編碼是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 常識 的確很有用

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM