我想请教一个问题
就是捕捉键盘事件时
怎么获取输入的每一个键?
比如我知道回车是vbenter
那其他所有的键呢?
我想请教一个问题
就是捕捉键盘事件时
怎么获取输入的每一个键?
比如我知道回车是vbenter
那其他所有的键呢?
看msdn,里面全有
我写了一个函数,可以在KeyDown事件里调用,获得按键名
Public Function GetKeyName(KeyCode As Integer) As String Dim SpStr As String Dim ArrSp() As String Select Case KeyCode Case 0 GetKeyName = "无" Case 8 GetKeyName = "BACKSPACE" Case 9 GetKeyName = "TAB" Case 12 GetKeyName = "CLEAR" Case 13 GetKeyName = "ENTER" Case 16 To 20 SpStr = "Shift|Ctrl|Alt|Pause|Caps Lock" ArrSp = Split(SpStr, "|") GetKeyName = ArrSp(KeyCode - 16) Case 27 GetKeyName = "Esc" Case 32 To 47 SpStr = "空格|Page Up|Page Down|End|Home|左方向键|上方向键|右方向键|下方向键|SELECT|SNAPSHOT|EXECUTE|Print Screen|Insert|Delete|Help" ArrSp = Split(SpStr, "|") GetKeyName = ArrSp(KeyCode - 32) Case 48 To 57, 65 To 90 '0-9,A-Z GetKeyName = Chr(KeyCode) Case 92 GetKeyName = "Win" Case 93 GetKeyName = "Right Mouse Key" Case 96 To 105 'NumPad0-9 GetKeyName = "NumPad" & Chr(KeyCode - 48) Case 108 GetKeyName = "NumPad Enter" 'NumPad Enter Case 106 To 111 'NumPad *,+,Enter,-,.,/ GetKeyName = "NumPad" & Mid("*+ -./", KeyCode - 105, 1) Case 112 To 127 'F1-F16 GetKeyName = "F" & KeyCode - 111 Case 144 GetKeyName = "Num Lock" Case 145 GetKeyName = "Scroll Lock" Case 187 GetKeyName = "=" Case 189 GetKeyName = "-" Case 192 GetKeyName = "`" Case 220 GetKeyName = "\" Case Else GetKeyName = "KeyCode:" & KeyCode End Select End Function