官方手册android
http://www.touchsprite.com/helpdoc#/doc?id=2148c#
小知识:手册的查询功能浏览器
注意 这里能精确的查询对应函数 可是没法模糊查询 好比记不起某个函数名 可是记得函数的说明的几个关键字 这样的模糊查询并不支持 服务器
触动精灵的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函数
触动的三款软件的优劣
三个软件均可以实现咱们的脚本功能
小精灵 免费的不支持网络插件和高级扩展库 放弃小精灵 收费的每个月5.5/台
触动企业版 收费很贵 按天收费 依然不考虑
触动精灵app 安卓免费 IOS收费 把脚本上传到手机上直接运行就好 或者生成二维码让手机扫码 问题是源码也有暴露的危险 暴露源码 可是能够对源码加密tsp文件 只能推荐这个了
三个软件在功能上区别
触动专业版在批量控制就是中控上官方已经提供了这服务 其余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