VB关于键盘响应的问题
以下的代码是一个“显示用户在窗体上的按键”的程序代码。
但是不明白其中的3句是什么意思,有高手能指点下小弟吗?已经在代码中标出~~~~~~
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim shiftdown, altdown, ctrldown
Dim txt As String
shiftdown = (Shift And vbShiftMask) > 0 ——这句
altdown = (Shift And vbAltMask) > 0——为什么是Shift而不是Alt
ctrldown = (Shift And vbCtrlMask) > 0——同样为何不是Ctrl
If KeyCode <= 90 And KeyCode >= 65 Then
If shiftdown And ctrldown And altdown Then
txt = "SHIFT+ALT+CTRL+"
ElseIf shiftdown And altdown Then
txt = "SHIFT+ALT+"
ElseIf shiftdown And ctrldown Then
txt = "SHIFT+CTRL+"
ElseIf ctrldown And altdown Then
txt = "CTRL+ALT+"
ElseIf shiftdown Then
txt = "SHIFT+"
ElseIf ctrldown Then
txt = "CTRL+"
ElseIf altdown Then
txt = "ALT+"
ElseIf Shift = 0 Then
txt = ""
End If
txt = txt + Chr(KeyCode)
Text1.Text = "You Press" & txt
End If
End Sub
参考答案:vbShiftMask SHIFT 键被按下。
vbCtrlMask CTRL 键被按下。
vbAltMask ALT 键被按下。
为什么是Shift而不是Alt 不是ctrl,原因很简单,看到过程的参数表了么,因为参数是shift