找回密码
 加入
搜索
查看: 2575|回复: 0

[原创] 折腾了一会了AutoScriptWriter,最后发现没什么用!

[复制链接]
发表于 2018-3-15 21:50:15 | 显示全部楼层 |阅读模式
本帖最后由 nhnhwsnh 于 2018-3-15 21:52 编辑

ahk有个AutoScriptWriter,可以录制代码,

但是au3的Au3Record.exe已经不能用了,

我就有个思路把AutoScriptWriter录的代码 转成au3代码


所以写了下面的东东,我还得意的一会
#include <Array.au3>
#include <File.au3>
#include <Array.au3>
Global $bFlag = True
;~ 第一步:选择文件
Local $sExeFilePath = FileSaveDialog("第一步:选择文件", @DesktopDir, "应用程序(*.exe)|所有文件 (*.*)")
Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = ""
Local $aPathSplit = _PathSplit($sExeFilePath, $sDrive, $sDir, $sFileName, $sExtension)
Global $sExeFileDir = $aPathSplit[1] & $aPathSplit[2]
Global $sExeFileName = $aPathSplit[3]
If FileExists($sExeFileDir & $sExeFileName & "_test.ahk") Then
        If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
        $iMsgBoxAnswer = MsgBox(36, "提示", $sExeFileName & "_test.ahk 已经存在!" & @CRLF & "是=删之,重新录制" & @CRLF & "否=不删,继续录制", 3)
        If $iMsgBoxAnswer <> 7 Then ;不是No,就删
                FileDelete($sExeFileDir & $sExeFileName & "_test.ahk")
        EndIf
EndIf
If FileExists($sExeFileDir & $sExeFileName & "_test.au3") Then
        If Not IsDeclared("iMsgBoxAnswer") Then Local $iMBoxAnswer
        $iMsgBoxAnswer = MsgBox(36, "提示", $sExeFileName & "_test.au3 已经存在!" & @CRLF & "是=删之,重新录制" & @CRLF & "否=不删,继续录制", 3)
        If $iMsgBoxAnswer <> 7 Then ;不是No,就删
                FileDelete($sExeFileDir & $sExeFileName & "_test.au3")
        EndIf
EndIf
;~ 第二步是否记录WindowText
#Region --- CodeWizard generated code Start ---
        Global $bWindowText
        ;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes and No, Icon=Question, Timeout=3 ss
        If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
        $iMsgBoxAnswer = MsgBox(36, "第二步", "是否记录WindowText", 3)
        Select
                Case $iMsgBoxAnswer = 6 ;Yes
                        $bWindowText = True
                Case $iMsgBoxAnswer = 7 ;No
                        $bWindowText = False
                Case $iMsgBoxAnswer = -1 ;Timeout
                        $bWindowText = True
        EndSelect
#EndRegion --- CodeWizard generated code Start ---

;~ 第三步设置鼠标速度
#Region --- CodeWizard generated code Start ---
        Global $iMouseSpeed
        ;InputBox features: Title=Yes, Prompt=Yes, Default Text=Yes, Input Length=3, TimeOut=3 ss, Width=200, Height=150, Left=500, Top=500
        If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
        $sInputBoxAnswer = InputBox("第三步", "设置鼠标速度", "10", " 10", "200", "150", Default, Default, "30")
        Select
                Case @error = 0 ;OK - The string returned is valid
                        $iMouseSpeed = $sInputBoxAnswer
                Case @error = 1 ;The Cancel button was pushed
                        $iMouseSpeed = 10
                Case @error = 2 ;The Timeout time was reached
                        $iMouseSpeed = 10
                Case @error = 3 ;The InputBox failed to open
                        $iMouseSpeed = 10
        EndSelect
#EndRegion --- CodeWizard generated code Start ---
;~ 设置已完成! 是否开始录制?
ToolTip("ExeFileName=" & $sExeFileName & ".exe" & @CRLF & _
                "WindowText=" & $bWindowText & @CRLF & _
                "MouseSpeed=" & $iMouseSpeed & @CRLF & _
                "", 0, 0)
If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(36, "提示", "设置已完成! 是否开始录制?" & @CRLF & "F10=开始/结束录制", 3)
If $iMsgBoxAnswer <> 7 Then ;不是No,就开始
        ahk2au3()
Else
        MsgBox(36, "提示", "点击F10,可以手动开始录制! ", 3)
EndIf
HotKeySet("{F10}", "ahk2au3")

While 1
        Sleep(100)
WEnd

Func ahk2au3()
        ToolTip("", 0, 0)
        If $bFlag Then
                Run(@ScriptDir & "\AutoScriptWriter.exe")
                WinWait("AutoScriptWriter II - ( by Larry Keys )", "")
                WinActivate("AutoScriptWriter II - ( by Larry Keys )", "")
                WinWaitActive("AutoScriptWriter II - ( by Larry Keys )", "")
                ControlSetText("AutoScriptWriter II - ( by Larry Keys )", "", "[CLASSNN:Edit1]", $sExeFilePath)
                If $bWindowText Then
                        ControlClick("AutoScriptWriter II - ( by Larry Keys )", "", "[TEXT:Window &Text]")
                EndIf
                ControlClick("AutoScriptWriter II - ( by Larry Keys )", "", "Button1")
                $bFlag = False
        Else
                ControlClick("AutoScriptWriter II - ( by Larry Keys )", "", "Button2")
                Local $sFilePath = $sExeFileDir & $sExeFileName & "_test.ahk"
                Local $sScipt = ControlGetText("AutoScriptWriter II - ( by Larry Keys )", "", "Edit2")
                FileWrite($sFilePath, $sScipt & @CRLF)
                WinClose("AutoScriptWriter II - ( by Larry Keys )", "")
                Local $aTEXT[0]
                _FileReadToArray($sFilePath, $aTEXT, $FRTA_NOCOUNT + $FRTA_INTARRAYS, ",")
                Local $i
                Local $sResult
                $sResult &= ";~         page.code:       coding: utf-8     copy this line to the first line" & @CRLF
                $sResult &= 'opt("MouseCoordMode",0)' & @CRLF
                For $i = 0 To UBound($aTEXT) - 1
                        Local $aLineText[0]
                        $aLineText = $aTEXT[$i]
;~         ConsoleWrite($aLineText[0] & @CRLF)
                        Local $j
                        For $j = 1 To UBound($aLineText) - 1
                                $aLineText[$j] = StringTrimLeft($aLineText[$j], 1)
                        Next
                        Switch $aLineText[0]
                                Case "Run"
                                        $sResult &= 'Run("' & $aLineText[1] & '")' & @CRLF
                                Case "WinWait"
                                        $sResult &= 'WinWait("' & $aLineText[1] & '","' & $aLineText[2] & '")' & @CRLF
                                Case "IfWinNotActive"
                                        $sResult &= 'if WinActive("' & $aLineText[1] & '","' & $aLineText[2] & '")=0 then' & @CRLF
                                        $sResult &= 'WinActivate("' & $aLineText[1] & '","' & $aLineText[2] & '")' & @CRLF
                                        $sResult &= 'endif' & @CRLF
                                Case "WinWaitActive"
                                        $sResult &= 'WinWaitActive("' & $aLineText[1] & '","' & $aLineText[2] & '")' & @CRLF
                                Case "MouseClick"
                                        $sResult &= 'MouseClick("' & $aLineText[1] & '",' & $aLineText[2] & "," & $aLineText[3] & ",1," & $iMouseSpeed & ')' & @CRLF
                                Case "Sleep"
                                        $sResult &= "sleep(" & $aLineText[1] & ")" & @CRLF
                                Case "Send"
                                        $sResult &= 'send("' & $aLineText[1] & '")' & @CRLF
                        EndSwitch
                Next
                $sResult &= 'tooltip("' & $sExeFileName & '.exe" & @CRLF & "脚本执行完毕!",0,0)' & @CRLF
                $sResult &= 'sleep(3000)' & @CRLF
                FileWrite($sExeFileDir & $sExeFileName & "_test.au3", $sResult & @CRLF)
                ShellExecute($sExeFileDir)
                Exit
        EndIf
EndFunc   ;==>ahk2au3
最后发现完全没必要的啊

只要把AU3record录制的代码略做修改就可以了
Opt("CaretCoordMode", 0)

;这里是AU3Record录制的代码

Func _WinWaitActivate($sTitle, $sText)
        Local $hWnd = WinWait($sTitle, $sText)
        If Not (WinActive($hWnd)) Then
                WinActivate($hWnd)
        EndIf
        WinWaitActive($hWnd)
EndFunc   ;==>_WinWaitActivate
分享给大家,就当是个乐子吧
我明明设置的金钱是0,怎么还是20个币才能下载呢?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-21 22:18 , Processed in 0.071042 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表