How to identify whi Shift, Ctrl or Alt key

zhaozj2021-02-16  104

Implement with API (GetasyncKeyState), valid under Win 2K, XP:

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As IntegerPrivate Const VK_LSHIFT = & HA0Private Const VK_RSHIFT = & HA1Private Const VK_LCTRL = & HA2Private Const VK_RCTRL = & HA3Private Const VK_LMENU = & HA4Private 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 pressedIf 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" If KeyCode = vbKeyControl And Shift = vbCtrlMask And (GetAsyncKeyState (VK_RCTRL) And & H8000) Then MsgBox "you click the Right Ctrl "

End Sub

Private sub form_load () me.keypreview = truend sub

转载请注明原文地址:https://www.9cbs.com/read-10571.html

New Post(0)