nhnhwsnh 发表于 2018-3-15 21:50:15

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

本帖最后由 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 & $aPathSplit
Global $sExeFileName = $aPathSplit
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 )", "", "", $sExeFilePath)
                If $bWindowText Then
                        ControlClick("AutoScriptWriter II - ( by Larry Keys )", "", "")
                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
                _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
                        $aLineText = $aTEXT[$i]
;~         ConsoleWrite($aLineText & @CRLF)
                        Local $j
                        For $j = 1 To UBound($aLineText) - 1
                                $aLineText[$j] = StringTrimLeft($aLineText[$j], 1)
                        Next
                        Switch $aLineText
                                Case "Run"
                                        $sResult &= 'Run("' & $aLineText & '")' & @CRLF
                                Case "WinWait"
                                        $sResult &= 'WinWait("' & $aLineText & '","' & $aLineText & '")' & @CRLF
                                Case "IfWinNotActive"
                                        $sResult &= 'if WinActive("' & $aLineText & '","' & $aLineText & '")=0 then' & @CRLF
                                        $sResult &= 'WinActivate("' & $aLineText & '","' & $aLineText & '")' & @CRLF
                                        $sResult &= 'endif' & @CRLF
                                Case "WinWaitActive"
                                        $sResult &= 'WinWaitActive("' & $aLineText & '","' & $aLineText & '")' & @CRLF
                                Case "MouseClick"
                                        $sResult &= 'MouseClick("' & $aLineText & '",' & $aLineText & "," & $aLineText & ",1," & $iMouseSpeed & ')' & @CRLF
                                Case "Sleep"
                                        $sResult &= "sleep(" & $aLineText & ")" & @CRLF
                                Case "Send"
                                        $sResult &= 'send("' & $aLineText & '")' & @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个币才能下载呢?
页: [1]
查看完整版本: 折腾了一会了AutoScriptWriter,最后发现没什么用!