|
如何识别键盘左右的shift,Ctrl或Alt键(1)
用API (GetAsyncKeyState)实现,在WIN 2K,XP 下有效: Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer Private Const VK_LSHIFT = &HA0 Private Const VK_RSHIFT = &HA1 Private Const VK_LCTRL = &HA2 Private Const VK_RCTRL = &HA3 Private Const VK_LMENU = &HA4 Private Const VK_RMENU = &HA5 Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = VBKeyShift And Shift = VBShiftMask And (GetAsyncKeyState(VK_LSHIFT) And &H8000) Then MsgBox "you click the Left Shift" If KeyCode = VBKeyShift And Shift = VBShiftMask And (GetAsyncKeyState(VK_RSHIFT) And &H8000) Then MsgBox "you click the RIGHT Shift" If KeyCode = VBKeyMenu And Shift = VBAltMask And (GetAsyncKeyState(VK_LMENU) And &H8000) Then MsgBox "you click the Left ALT" ' only ALT was pressed If KeyCode = VBKeyMenu And Shift = VBAltMask And (GetAsyncKeyState(VK_RMENU) And &H8000) Then MsgBox "you click the RIGHT ALT" ' only ALT was pressed If KeyCode = VBKeyControl And Shift = VBCtrlMask And (GetAsyncKeyState(VK_LCTRL) And &H8000) Then MsgBox "you click the Left CTRL"
|