Use AppActivate to change the active window

后端 未结 2 1983
感动是毒
感动是毒 2021-01-20 10:19

I\'m am trying to send some keystrokes to a program. I have some example code below which works fine up until the final {Alt} command. I believe this is due to

2条回答
  •  无人及你
    2021-01-20 11:00

    Each windows process has an identifier. If you store the process id for each notepad window, you can avoid worrying about finding the right window after its title changes.

    Here is an example of opening two notepad files, activating by process id and sending keys.

    Set objShell = WScript.CreateObject("WScript.Shell")
    
    Function SendKeysTo (process, keys, wait)
        objShell.AppActivate(process.ProcessID)
        objShell.SendKeys keys
        WScript.Sleep wait
    End Function
    
    Set notepadA= objShell.Exec("notepad")
    Set notepadB= objShell.Exec("notepad")
    WScript.Sleep 500
    
    
    SendKeysTo notepadA, "Hello I am Notepad A", 1000
    SendKeysTo notepadB, "Hello I am Notepad B", 1000
    

    Hopefully you can take a similar approach to solve your problem.

提交回复
热议问题