(我问的是vb示例,但c#也是如此,答案也是一样的。(
我正试图使用dotnetbrowser填写表格,但在理解keychar和keycode/virtalkey参数中到底应该放什么时遇到了问题;按下";特殊键,如";向下箭头"选项卡"输入";。";KeyCode枚举";表列表,例如;选项卡(9(";,返回(13("向下箭头(40("A(65(〃;。因此,要键入A,我需要执行以下操作:
SimulateKey(keyboard, 65, "A")
或者,只是写得不一样,
SimulateKey(keyboard, 65, chr(65))
这对于";A";,和
SimulateKey(keyboard, 97, chr(97))
对";a";,尽管我不明白为什么,因为97是";Numpad1";。
但是,当我想键入tab-return-down-A时,我应该为特殊字符的keychar指定什么?
SimulateKey(keyboard, 9, chr(9))
SimulateKey(keyboard, 13, chr(13))
SimulateKey(keyboard, 40, chr(40)) 'where chr(40) is actually an opening parantheses "("
SimulateKey(keyboard, 65, chr(65))
或者keychar是空的,或者是等特殊字符的空格
SimulateKey(keyboard, 9, "") 'nothing between the qoutes
SimulateKey(keyboard, 13, " ") 'space-character (asc 32) between the quotes
当我真的想键入一个开放的paranthes"时,我需要特别说明什么;(",它是asc 40,因此具有与down相同的代码?我希望能对keycode和keychar值进行详尽的解释。
为了完整起见,这是我用于SimulateKey的代码(来自vb dotnetbrowser示例或此处为c#(
Private Shared Sub SimulateKey(keyboard As IKeyboard, key As KeyCode, keyChar As String, Optional ByVal modifiers As KeyModifiers = Nothing)
modifiers = If(modifiers, New KeyModifiers())
Dim keyPressedEventArgs = New KeyPressedEventArgs With {
.KeyChar = keyChar,
.VirtualKey = key,
.Modifiers = modifiers
}
Dim keyTypedEventArgs = New KeyTypedEventArgs With {
.KeyChar = keyChar,
.VirtualKey = key,
.Modifiers = modifiers
}
Dim keyReleasedEventArgs = New KeyReleasedEventArgs With {
.VirtualKey = key,
.Modifiers = modifiers
}
keyboard.KeyPressed.Raise(keyPressedEventArgs)
keyboard.KeyTyped.Raise(keyTypedEventArgs)
keyboard.KeyReleased.Raise(keyReleasedEventArgs)
End Sub
密钥代码是Windows虚拟密钥代码,在此处列出。
这些代码表示键盘上的物理键,而不是字符。要区分使用同一个键的两个字符(如A和A,或(和9