您的位置:首页 > 编程语言 > VB

.net随笔-vb.net打开外部程序发送键盘信号(1)

2019-03-27 09:34 239 查看
版权声明:本博客所有文章版权归博主刘兴所有,转载请注意来源 https://blog.csdn.net/AI_LX/article/details/88836740
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim notepadID As Integer
' 下面可激活一个运行中的程序
'AppActivate("无标题 - 记事本")
' 通过shell函数运行一个新实例
notepadID = Shell("NOTEPAD.EXE", AppWinStyle.NormalFocus)
AppActivate(notepadID)
My.Computer.Keyboard.SendKeys("您好,世界!", True)
End Sub
End Class


C#
public void SendKeys (string keys, bool wait);
Parameters
keys
String
A String that defines the keys to send.
wait
Boolean
Optional. A Boolean that specifies whether or not to wait for keystrokes to get processed before the application continues. True by default.
Exceptions
SecurityException
A partial-trust situation exists in which the user lacks necessary permissions

因为没有托管方法来激活另一个应用程序,所以您可以在当前应用程序中使用该类,手动选择要向其发送密钥的窗口,或者使用Windows API方法(如FindWindow和SetForegroundWindow)强制将焦点移动到其他应用程序上

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: