如何:启动应用程序并向其发送击键 (Visual Basic)
本示例使用 Shell 方法启动记事本应用程序,然后使用 My.Computer.Keyboard.SendKeys 方法发送击键来打印句子。
示例
Dim ProcID As Integer
' Start the Notepad application, and store the process id.
ProcID = Shell("NOTEPAD.EXE", AppWinStyle.NormalFocus)
' Activate the Notepad application.
AppActivate(ProcID)
' Send the keystrokes to the Notepad application.
My.Computer.Keyboard.SendKeys("I ", True)
My.Computer.Keyboard.SendKeys("♥", True)
My.Computer.Keyboard.SendKeys(" Visual Basic!", True)
' The sentence I ♥ Visual Basic! is printed on Notepad.
可靠编程
如果找不到具有请求的进程标识符的应用程序,则会引发 ArgumentException 异常。
.NET Framework 安全性
对 Shell
函数的调用需要完全信任(SecurityException 类)。
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈