我有一个应用程序,在其中我得到一个“另存为”对话框。有时,如果存在同名的文件,则会出现另一个同名的对话框“另存为”。以下是我写的代码,但它不能像预期的那样工作。
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的文件,并尝试以相同的名称保存一个文件,您将得到另一个名称为“另存为”的对话框。
发布于 2014-03-20 21:08:21
试试这个:
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 ;==>Examplehttps://stackoverflow.com/questions/22461209
复制相似问题