在网上拷了一段模拟按键的代码,模拟按下Shift+空格,放到事件里去可用。
Dim typeForKeywords As Type = Type.[Gettype]("System.Windows.Forms.SendKeys+KeywordVk[], System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
Dim typeForKeywordItem As Type = Type.[Gettype]("System.Windows.Forms.SendKeys+KeywordVk, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
Dim objNewKey As Object = Activator.CreateInstance(typeForKeywordItem, "SPACE", &H20)
Dim typeForSendKeys As Type = Gettype(SendKeys)
Dim fieldForkeywords As System.Reflection.FieldInfo = typeForSendKeys.GetField("keywords", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.GetField Or System.Reflection.BindingFlags.[Static])
Dim objKeys As Object = fieldForkeywords.GetValue(Nothing)
Dim typeForlistForKeyword As Type = Type.[Gettype]("System.Collections.Generic.List`1[[System.Windows.Forms.SendKeys+KeywordVk, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
Dim objForTmpKeyWords As Object = Activator.CreateInstance(typeForlistForKeyword)
Dim mi As System.Reflection.MethodInfo = typeForlistForKeyword.GetMethod("Add")
For Each var As Object In DirectCast(objKeys, Array)
'list.Add(var);
mi.Invoke(objForTmpKeyWords, New Object() {var})
Next
'list.Add(key);
mi.Invoke(objForTmpKeyWords, New Object() {objNewKey})
mi = typeForlistForKeyword.GetMethod("ToArray")
Dim objArray As Object = mi.Invoke(objForTmpKeyWords, Nothing)
fieldForkeywords.SetValue(Nothing, objArray)
SendKeys.Send("+{Space}")
[此贴子已经被作者于2012-10-11 12:03:52编辑过]