[摘要]VB.Net中使用Sendkeys遥控:  大家在VB6中都用过sendkeys,幕通过发送键盘的事件间接地控制外部程序,是有遥控之说。  我在VB7中却发现这个不能用了, 也就不了了之,  后来一...
VB.Net中使用Sendkeys遥控:  
大家在VB6中都用过sendkeys,幕通过发送键盘的事件间接地控制外部程序,是有遥控之说。  
我在VB7中却发现这个不能用了, 也就不了了之,  
后来一次在查阅MSDN的时候竟看到了这个,是以尝试了一下,竟然旧貌新颜,还是一样好用。  
主要是在system.winforms族中找到sendkeys 使用方法同VB6  
键:一般的字符键如下输入”A” “B” “C”………………”Z”等,如果要连续按下两个以上就使用”AB”的形式  
如果同时按下AB就使用括号如”(AB)”  
如果是功能键,就放到大括号中如“{F4}” 另:用+代表Shift,用^代表Ctrl,用%代表Alt  
如“+A”表示按下Shift同时按A  
下面是一个例子:  
Dim sdstr As System.WinForms.SendKeys  
sdstr.Send("%{F4}") 发送ALT+F4     
下面这个代码在按下Button2以后转移焦点到下一个控件,      
使按钮能按下又不能按受焦点.  
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)  
Dim sdstr As System.WinForms.SendKeys  
sdstr.Send("{TAB}")  
End Sub  
下面使用SendWait,使用的方法同上,不过执行这个过程会等待到发送的键执行完成以后,再继续执行后面的代码.  
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)  
Dim sdstr As System.WinForms.SendKeys  
'sdstr.Send("{TAB}")  
sdstr.SendWait("{TAB}")  
End Sub     
VB.NET中使用shell调用外部程序:  
Shell(pathname as string,[style as microsoft.visualbasic.appwinstyle=2],[wait as boolean=false],[timeout as integer=-1]) as integer  
调用资源管理器  
Dim PID As Integer  
PID = Shell("explorer.exe http://vbnetcn.126.com", Microsoft.VisualBasic.AppWinStyle.NormalFocus, True)  
调用默认程序  
Dim PID As Integer  
PID = Shell("start.exe mailto:vbnetcn@163.com", Microsoft.VisualBasic.AppWinStyle.Hide, True)  
使用Microsoft.VisualBasic.AppWinStyle.Hide参数是为了隐藏程序运行时跳出的DOS窗口    
关键词:SendKeys办法与Shell函数