zoukankan      html  css  js  c++  java
  • 如何识别键盘左右的shift,Ctrl或Alt键

    用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"
    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 = True
    End Sub

  • 相关阅读:
    西藏之行的一点总结
    《吃的法则》总结
    《心法》总结
    分布式系统中的CAP、ACID、BASE概念
    《你当像鸟飞往你的山》总结
    《怪诞行为学》总结
    编程的一些抽象核心
    《活法》总结
    Mac使用Charles给iPhone抓包流程
    《认知天性》总结
  • 原文地址:https://www.cnblogs.com/fengju/p/6336380.html
Copyright © 2011-2022 走看看