本文介绍了使用 AppActivate 更改活动窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向程序发送一些按键.我在下面有一些示例代码,它可以正常工作,直到最后的 {Alt} 命令.我相信这是由于窗口名称从 "Notepad1" 更改为 "NotePad2" 所致.谁能帮我在 objShell.SendKeys "{Enter}" 命令之后将 AppActivate 路径更改为 "Notepad2"?

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 the window name changing from "Notepad1" to "NotePad2". Could anyone help me change the AppActivate path to "Notepad2" after the objShell.SendKeys "{Enter}" command?

示例:

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "Notepad.exe"
Do Until Success = True
Success = objShell.AppActivate("NotepadPathA")
Loop
objShell.SendKeys "{F1}"
objShell.SendKeys "Secure06**"
objShell.SendKeys "{Enter}"
Shell.SendKeys "{Alt}"

推荐答案

  1. 您在最后一行使用了 Shell 但尚未定义它.将其改为 objShell.
  2. 要发送 Alt 键,请使用 "%".例如:

  1. You're using Shell on your last line but you haven't defined it. Change it to objShell instead.
  2. To send the Alt key, use "%". For example:

objShell.SendKeys "%"

您通常会在组合键中使用它.例如,要在大多数程序中打开 File 菜单,您可以使用 Alt+F,或:

You would typically use this in a key combination. For example, to open the File menu in most programs, you would use Alt+F, or:

objShell.SendKeys "%f"

  • 如果您的窗口标题发生变化,或者您出于任何原因需要激活一个新窗口,只需再次调用 AppActivate:

    objShell.AppActivate "My new window title"
    

  • 这篇关于使用 AppActivate 更改活动窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    08-15 07:34