请问有谁知道键盘模拟输入时,模拟输入+ - * / . , : ; ' " ? / \ `~ ! @ # $ % ^ & { } [ ] ( ) - _ | 等字符啊
用下面代码可以显示键盘所有ASCII码
Private Declare Function GetWindowThreadProcessId& Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long)
Private Declare Function GetKeyboardLayout& Lib "user32" (ByVal dwLayout As Long)
Private Declare Function MapVirtualKeyEx Lib "user32" Alias "MapVirtualKeyExA" (ByVal uCode As Long, ByVal uMapType As Long, ByVal dwhkl As Long) As Long
Private Function CharFromKeyCode(k As Integer) As String
Dim s As String
Select Case k
Case vbKeyBack: s = "BackSpace"
Case vbKeyTab: s = "Tab"
Case vbKeyClear: s = "Clear"
Case vbKeyReturn: s = "Enter"
Case vbKeyShift: s = "Shift"
Case vbKeyControl: s = "Ctrl"
Case vbKeyMenu: s = "Alt"
Case vbKeyPause: s = "Pause"
Case vbKeyCapital: s = "CapsLock"
Case vbKeyEscape: s = "ESC"
Case vbKeySpace: s = "SPACEBAR"
Case vbKeyPageUp: s = "PAGE UP"
Case vbKeyPageDown: s = "PAGE DOWN"
Case vbKeyEnd: s = "END"
Case vbKeyHome: s = "HOME"
Case vbKeyLeft: s = "LEFT ARROW"
Case vbKeyUp: s = "UP ARROW"
Case vbKeyRight: s = "RIGHT ARROW"
Case vbKeyDown: s = "DOWN ARROW"
Case vbKeySelect: s = "SELECT"
Case vbKeyPrint: s = "PRINT SCREEN"
Case vbKeyExecute: s = "EXECUTE"
Case vbKeySnapshot: s = "SNAPSHOT"
Case vbKeyInsert: s = "INS"
Case vbKeyDelete: s = "DEL"
Case vbKeyHelp: s = "HELP"
Case vbKeyNumlock: s = "NUM LOCK"
Case vbKey0 To vbKey9: s = Chr$(k)
Case vbKeyA To vbKeyZ: s = Chr$(MapVirtualKeyEx(k, 2, GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow, 0))))
Case vbKeyF1 To vbKeyF16: s = "F" & CStr(k - 111)
Case vbKeyNumpad0 To vbKeyNumpad9: s = "Numpad " & CStr(k - 95)
Case vbKeyMultiply: s = "Numpad {*}"
Case vbKeyAdd: s = "Numpad {+}"
Case vbKeySeparator: s = "Numpad {ENTER}"
Case vbKeySubtract: s = "Numpad {-}"
Case vbKeyDecimal: s = "Numpad {.}"
Case vbKeyDivide: s = "Numpad {/}"
Case Else
s = Chr$(MapVirtualKeyEx(k, 2, GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow, 0))))
End Select
CharFromKeyCode = s
End Function
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim s As String
s = "KeyCode " & KeyCode
s = s + " " & CharFromKeyCode(KeyCode)
If Shift = vbShiftMask Then s = s & " + Shift "
If Shift = vbCtrlMask Then s = s & " + Ctrl "
If Shift = vbAltMask Then s = s & " + Alt "
Print vbCrLf & s & " Down "
End Sub