开发中的自动化——按键精灵&AutoIt

来源:互联网 发布:mac版的优酷能缓存吗 编辑:程序博客网 时间:2024/05/18 01:47

游戏开发中经常需要发布版本给策划测试,可以用svn或者ftp等来做为文件传输的渠道。

我们这边的流程一般如下:

1、在flash builder构建发布版本。

2、用Beyond Compare(文件对比工具)对比发布目录和策划测试目录里面的程序,并且把新的文件拷贝到测试目录中。

3、对比游戏资源目录和策划测试资源目录,并且把新的资源拷贝过去。

4、提交测试目录到svn。

这其中第1步有3次鼠标操作和等待时间,第2步中有3次鼠标操作和较短等待时间,第3步和第2步鼠标操作一样,但如果资源多的话就要等很久了。

每次都这样点还要等太烦了,一键操作多方便的啊。

 

按键精灵被很多人用来做辅助程序,当然拿来做点自动化的小工具还是不错的选择。2011年的时候同事用按键精灵来处理flash cs做界面处理的重复操作,当时他并没有编写脚本,而是用的录制宏的方式来处理的,实际中让宏循环执行时,还借助了记事本来提供一些数据。

开始接触AutoIt是大概2010年左右,原本想找一个类似shell的脚本,来帮助我在编译动态库生成后拷贝文件后,再提交svn。转换动画文件转换后自动拷贝资源,并且提交svn。但看到autoit语法太麻烦了还是没有弄。

先用按键精灵实现了一个版本,要求flash builder和beyond compare已经启动。如果让脚本来启动程序再操作,感觉太麻烦了,还要配置路径(同事电脑上面路径可能不一样),就手动先让程序都跑起来。在beyond compare中选择文件夹同步时是根据坐标计算的,用文字识别来肯定好些,但是麻烦啊~

这个按键精灵的版本在2个同事电脑上面测试,一个正常一个不正常,估计是电脑计时引起的差异。用按键精灵可以直接用脚本文件跑,不必导出小精灵,导出小精灵还有广告。有广告太烦了,所以又用autoit照着写了个。

[General]SyntaxVersion=2BeginHotkey=121BeginHotkeyMod=0PauseHotkey=0PauseHotkeyMod=0StopHotkey=123StopHotkeyMod=0RunOnce=1EnableWindow=MacroID=f3353dc6-1d9e-4d6d-abb5-77b2fcda5516Description=同步到testEnable=1AutoRun=0[Repeat]Type=0Number=1[SetupUI]Type=2QUI=[Relative]SetupOCXFile=[Comment]【功能说明】发布程序时一键操作让flash builder发布版本,然后同步到test目录【使用说明】先把flash builder和Beyond Compare开启,然后运行等待完成就可以提交了[Script]Call 构建发布版()Call test同步()MessageBox "同步test完成"///////////////////////////////////////////////////////////////////////////////////////////构建发布版Sub 构建发布版()    HwndEx = Plugin.Window.Search("Flash Builder")    MyArray = Split(HwndEx, "|")       If UBound(MyArray)>=0 Then          Hwnd = Clng(MyArray(0))        Call Plugin.Window.Max(Hwnd)        Delay 100        Call Plugin.Window.Active(Hwnd)        Delay 100        sRect = Plugin.Window.GetClientRect(Hwnd)        MyArray = Split(sRect, "|")          W1 = Clng(MyArray(0)) : H1 = Clng(MyArray(1))        //    MsgBox "边框大小:       "  &  W1 & "             " & H1         //选择导出        MoveTo W1+385, H1+15        Delay 100        LeftClick 1        Delay 100        //开始导出        Do While True            DochuHwnd = Plugin.Window.Foreground()            If DochuHwnd <> Hwnd Then                 Delay 500                Exit Do            End If            Delay 100        Loop        //    sText = Plugin.Window.GetText(DochuHwnd)        //    MsgBox sText         sRect = Plugin.Window.GetClientRect(DochuHwnd)        MyArray = Split(sRect, "|")          DochuW1 = Clng(MyArray(0)) : DochuH1 = Clng(MyArray(1))        // MsgBox "边框大小:" & DochuW1 & "," & DochuH1        MoveTo DochuW1+475, DochuH1+630        Delay 100        LeftClick 1        Delay 100        //检测导出是否完成        Do While True            WanchengHwnd = Plugin.Window.Foreground()            If WanchengHwnd <> DochuHwnd Then                 Delay 500                Exit Do            End If            Delay 100        Loop        sRect = Plugin.Window.GetClientRect(WanchengHwnd)        MyArray = Split(sRect, "|")          WanchengW1 = Clng(MyArray(0)) : WanchengH1 = Clng(MyArray(1))        // MsgBox "边框大小:" & WanchengW1 & "," & WanchengH1        MoveTo WanchengW1+372, WanchengH1+134        Delay 500        LeftClick 1        Delay 100    Else         Msgbox "未启动flash builder"        EndScript    End If   End Sub//同步文件夹Sub 同步文件夹()    Delay 100    //等待进入同步界面选择同步    Do While True        GetColor = GetPixelColor(W1 + 19, H1 + 41)        //MsgBox W1 & H1 & GetColor        If GetColor = "40D0FF" Then             Delay 500            Exit Do        End If        Delay 100    Loop    //MsgBox "开始同步"    //等待对比同步完成    Do While True        GetColor=GetPixelColor(W1+22, H1+308)        If GetColor <> "2B53FD" Then             Delay 500            Exit Do        End If        Delay 100    Loop//    MsgBox "对比完成"    //判断是否需要同步    GetColor = GetPixelColor(W1 + 1267, H1 + 347)    If GetColor = "2BBF6D" Then         Delay 500        //点击同步        MoveTo W1 + 1267, H1 + 347        Delay 100        LeftClick 1        Delay 100        //等待同步完成        Do While True            GetColor=GetPixelColor(W1+15, H1+462)            If GetColor = "82DAF4" Then                 Delay 500                //MsgBox "同步完成"                Exit Do            End If            Delay 100        Loop    End If    Delay 100    //返回    MoveTo W1+19, H1+41    Delay 100    LeftClick 1    Delay 100End SubSub test同步()    //对文件进行拷贝    HwndEx = Plugin.Window.Search("Beyond Compare")    MyArray = Split(HwndEx, "|")       If UBound(MyArray)>=0 Then          Hwnd = Clng(MyArray(0))        Call Plugin.Window.Max(Hwnd)        Delay 100        Call Plugin.Window.Active(Hwnd)        Delay 100        //    sRect = Plugin.Window.GetWindowRect(Hwnd)        sRect = Plugin.Window.GetClientRect(Hwnd)        MyArray = Split(sRect, "|")          W1 = Clng(MyArray(0)) : H1 = Clng(MyArray(1))        //确保在最开始界面返回        MoveTo W1+19, H1+41        Delay 100        LeftClick 1        Delay 100        //同步test程序        MoveTo W1+367, H1+444        Delay 100        LeftClick 1        Delay 20        LeftClick 1        Delay 100        Call 同步文件夹()         //同步test资源        MoveTo W1+354, H1+427        Delay 100        LeftClick 1        Delay 20        LeftClick 1        Delay 100        Call 同步文件夹()    Else         Msgbox "未启动Beyond Compare"        EndScript    End IfEnd Sub

 

autoit版本的鼠标移动是有轨迹移动的,不是瞬移,在按键的时候应该会好些。导出一个exe随便哪都可以用了。

;同步到testBuildRelease()SyncTest()MsgBox(0,"提示","同步test完成");构建发行版本Func BuildRelease()Local $hwnd = WinGetHandle("[REGEXPTITLE:[\s\S]+Flash Builder]");MsgBox(0, "Details", WinGetTitle($hwnd))If $hwnd <> "" Then   WinSetState($hwnd, "", @SW_MAXIMIZE)   Sleep(100)   WinActivate($hwnd)   Sleep(100)   Local $size = WinGetPos($hwnd)   ;MsgBox(0, "Active window stats (x,y,width,height):", $size[0] & " " & $size[1] & " " & $size[2] & " " & $size[3])   Local $x=$size[0]   Local $y=$size[1]   ;选择导出   MouseMove($x+396, $y+65,5)   Sleep(100)   MouseClick("left")   Sleep(100)   ;开始导出   WinWaitActive("导出发行版")   $hwnd = WinGetHandle("导出发行版")   ;//MsgBox(0,"句柄",$hwnd)   $size = WinGetPos($hwnd)   $x=$size[0]   $y=$size[1]   MouseMove($x+473, $y+659,5)   Sleep(100)   MouseClick("left")   ;检测导出是否完成   WinWaitNotActive($hwnd)   Local $wanchen = WinGetHandle("导出发行版")   ;//MsgBox(0,"句柄",$wanchen)   $size = WinGetPos($wanchen)   $x=$size[0]   $y=$size[1]   MouseMove($x+374, $y+167,5)   Sleep(100)   MouseClick("left")   Sleep(500)Else   MsgBox(0,"错误","未启动flash builder")   ExitEndIfEndFunc;同步文件夹Func SyncDir($x,$y,$hwnd)   ;//等待进入同步界面选择同步   Do  Sleep(100)  Local $Color=PixelGetColor($x+27, $y+71,$hwnd)  ;MsgBox(0,"color",Hex($Color,6))   Until $Color==0xffd040   ;//等待对比同步完成   Sleep(500)   Do  Sleep(100)  $Color=PixelGetColor($x+30, $y+338,$hwnd)   Until $Color<>0xfd532b   ;//判断是否需要同步   Sleep(500)   $Color=PixelGetColor($x+1275, $y+377,$hwnd)   If $Color==0x6dbf2b Then  ;//点击同步  MouseMove($x+1275, $y+377,5)  Sleep(100)  MouseClick("left")  Sleep(500)  ;//等待同步完成  Do Sleep(100) $Color=PixelGetColor($x+23, $y+492,$hwnd)  Until $Color==0xf4da82   EndIf   ;//返回   MouseMove($x+27, $y+71,5)   Sleep(100)   MouseClick("left")   Sleep(100)EndFunc;test同步Func SyncTest()Local $hwnd = WinGetHandle("[REGEXPTITLE:[\s\S]+Beyond Compare]");MsgBox(0, "Details", WinGetTitle($hwnd))If $hwnd <> "" Then   WinSetState($hwnd, "", @SW_MAXIMIZE)   Sleep(100)   WinActivate($hwnd)   Sleep(100)   Local $size = WinGetPos($hwnd)   ;MsgBox(0, "Active window stats (x,y,width,height):", $size[0] & " " & $size[1] & " " & $size[2] & " " & $size[3])   Local $x=$size[0]   Local $y=$size[1]   ;//确保在最开始界面返回   MouseMove($x+27, $y+71,0)   Sleep(100)   MouseClick("left")   Sleep(100)   ;//同步test程序   MouseMove($x+375, $y+474)   Sleep(100)   MouseClick("left")   Sleep(20)   MouseClick("left")   Sleep(100)   SyncDir($x,$y,$hwnd)   ;//同步test资源   MouseMove($x+362, $y+457)   Sleep(100)   MouseClick("left")   Sleep(20)   MouseClick("left")   Sleep(100)   SyncDir($x,$y,$hwnd)Else   MsgBox(0,"错误","未启动Beyond Compare")   ExitEndIfEndFunc

 

现在用着速度比人手工快多了。以后再也不用担心发布了~

0 0
原创粉丝点击