首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Autoit和记事本

Autoit和记事本
EN

Stack Overflow用户
提问于 2014-03-18 01:29:46
回答 1查看 2.4K关注 0票数 0

我有一个应用程序,在其中我得到一个“另存为”对话框。有时,如果存在同名的文件,则会出现另一个同名的对话框“另存为”。以下是我写的代码,但它不能像预期的那样工作。

代码语言:javascript
复制
Global $sTitle = "Save As"

WinWait($sTitle)
WinWaitActive($sTitle)

ControlClick($sTitle, "Save", "[CLASS:Button; TEXT:&Save; INSTANCE:2]")
ControlSetText($sTitle, "", "CLASS:Button; INSTANCE:2]", $file_name)

SendKeepActive($sTitle)
Send("{ENTER}")
Sleep(4000)
WinWaitActive($sTitle,"",3)

If WinExists($sTitle, "No") Then Send("{ENTER}")
If WinExists("Exit OmniPeek") Then
    Send("{ENTER}")
Else
    Sleep(2000)
    WinClose($closing_file)
EndIf

其想法是检查是否出现第二个“另存为”对话框,如果确实出现,则覆盖现有文件。然而,这似乎不适用于我编写的autoit脚本。

有人能帮我写这个脚本吗?您也可以使用记事本重新创建问题。只要有一个名称为abc.txt的文件,并尝试以相同的名称保存一个文件,您将得到另一个名称为“另存为”的对话框。

EN

回答 1

Stack Overflow用户

发布于 2014-03-20 21:08:21

试试这个:

代码语言:javascript
复制
Example()

Func Example()
    ; Run Notepad
    Run("notepad.exe")

    ; Wait 10 seconds for the Notepad window to appear.
    Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)

    ; Keep the Notepad window active when using the Send function.
    SendKeepActive("[CLASS:Notepad]")

    ; Simulate entering a string of text. If you try to change to a different window other than Notepad, then the Notepad window will
    ; be brought to focus again.
    For $i = 1 To 10
        Sleep(5)
        Send("notepad - ")
    Next

    ; Disable the Notepad window being active when using the Send function.
    SendKeepActive("")

    ; Close the Notepad window using the handle returned by WinWait.
    WinClose($hWnd)

    Send("{ENTER}") ; <<< SAVE

    ; Now a screen will pop up and ask to save the changes, the classname of the window is called
    ; "#32770" and simulating the "TAB" key to move to the second button in which the "ENTER" is simulated to not "save the file"
    WinWaitActive("[CLASS:#32770]", '', 2)
    Sleep(50)
    Send('newName.txt')
    Sleep(1000)
    Send("{TAB}{ENTER}")
EndFunc   ;==>Example
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22461209

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档