分类

  • 软件天地

  • 如何识别键盘左右的shift,Ctrl或Alt键‖
    tate)实现,在WIN 2K,XP 下
    有效:

      Private Declare Func
    As Integer
    tion GetAsyncKeyState Lib "u

    ser32" (ByVal vKey As Long)

      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_Key
    Down(KeyCode As Integer, Shi
    ft As Integer)
      If KeyCode = vbKeyShift And Shif
    AsyncKeyState(VK_LSHIFT) And &H8000)
    t = vbShiftMask And (Get

       Then MsgBox "you click the Left Shift"
      If KeyCode = vbKeyShift And Shif
    AsyncKeyState(VK_RSHIFT) And &H8000)
    t = vbShiftMask And (Get

      Then MsgBox "you click the RIGHT Shift"

      If KeyCode = vbKeyMe
    And &H8000)
    nu And Shift = vbAltMask And

    (GetAsyncKeyState(VK_LMENU)

      Then MsgBox "you click the Left
    ALT" ' only ALT was pressed
      If KeyCode = vbKeyMe
    And &H8000)
    nu And Shift = vbAltMask And

    (GetAsyncKeyState(VK_RMENU)

      Then MsgBox "you cli
    ck the RIGHT ALT" ' only ALT
    was pressed

      If KeyCode = vbKeyCo
    yState(VK_LCTRL) And &H8
    ntrol And Shift = vbCtrlMask
    000)
    And (GetAsyncKe

       Then MsgBox "you click the Left CTRL"  
      If KeyCode = vbKeyControl And Sh
    tAsyncKeyState(VK_RCTRL) And &H8000)
    ift = vbCtrlMask And (Ge

      Then MsgBox "you click the Right CTRL"  

      End Sub                                                                

      Private Sub Form_Load()                                
      Me.KeyPreview = True                                      
      End Sub                                                                



    上一页 下一页




    map