How to click a button using a batch file?

前端 未结 4 1153
天涯浪人
天涯浪人 2020-12-05 08:21

I need to click a button called \"save\" in a Adobe Air application called Arthropod. I can launch the app in the bat file with this:

cd C:\\Program Files\\A         


        
相关标签:
4条回答
  • 2020-12-05 08:57

    You cannot automate button clicks with a bat file. If it were possible, you would still need some kind of API for Adobe Air for access the control itself. But if there is a keyboard shortcut to this button, you can simulate a keystroke and send that to the application.

    0 讨论(0)
  • 2020-12-05 08:59

    You can use AutoIt to do this. You can generate a script that would click on the "Save" button, and call the generated EXE file from a batch file.

    0 讨论(0)
  • 2020-12-05 08:59

    There is no native way to do this cleanly.

    But you can use VBS to simulate keystrokes if you want, something similar to AutoIT, but nowhere as flexible. On the Plus side of things, you don't need to download VBS. It's been included in every version of Windows since 95.


    I am including an example that launches notepad.exe, then types the following into it:

    Hello World!
    abcDEF
    

    .
    The following single line is called LaunchNotepad.bat :

    cscript /nologo LaunchNotepad.vbs
    

    .
    The following is the contents of LaunchNotepad.vbs :

    ' Create WScript Shell Object to access filesystem.
    Set WshShell = WScript.CreateObject("WScript.Shell")
    
    ' Start / Run NOTEPAD.EXE
    WshShell.Run "%windir%\notepad.exe"
    
    ' Select, or bring Focus to a window named `NOTEPAD`
    WshShell.AppActivate "Notepad"
    
    ' Wait for 5 seconds
    WScript.Sleep 5000
    
    WshShell.SendKeys "Hello World!"
    WshShell.SendKeys "{ENTER}"
    WshShell.SendKeys "abc"
    WshShell.SendKeys "{CAPSLOCK}"
    WshShell.SendKeys "def"
    

    Note that if there is one or more instances of Notepad.exe already open, and it takes more than 5 seconds to open notepad, the above code may select the the last active instance of notepad and type into that.


    To get the VBS code to work how you want, you'll need to learn how to navigate around Adobe Air by keyboard. Usually either tabs and/or arrow-keys will suffice. Sometimes you may need to use the ALT key to move into the menus.

    Also, you might actually be able to use a series of keyboard commands like ALT+FSENTER, or even a keyboard shortcut like CTRL+S.

    To send TAB, ALT+F, and CTRL+S :

    WshShell.SendKeys "{TAB}"        ' TAB                TAB Key
    WshShell.SendKeys "%F"           ' ALT-F              (F)ile Menu
    WshShell.SendKeys "^S"           ' CTRL-S             Save File
    WshShell.SendKeys "%(Fa){ENTER}" ' ALT-F+ALT-A ENTER  (F)ile -> Save (A)s -> (ENTER)
    WshShell.SendKeys "{UP}"         ' Up Arrow           Up Arrow
    WshShell.SendKeys "{DOWN}"       ' Down Arrow         Down Arrow
    WshShell.SendKeys "{LEFT}"       ' Left Arrow         Left Arrow
    WshShell.SendKeys "{RIGHT}"      ' Right Arrow        Right Arrow
    
    0 讨论(0)
  • 2020-12-05 09:07

    Winbatch is another program that can send keystrokes, but unlike AutoIt I don't believe it's free.

    0 讨论(0)
提交回复
热议问题