使用 API 函数 GetKeyState 来判断 Ctrl、Shift 和 Alt 按键是否按下。
代码如下:
'用户昵称: 留下些什么
'个人简介: 一个会做软件的货代
'CSDN网址:https://blog.csdn.net/zezese
'电子邮箱:31319180@qq.com
Option Explicit
Private Declare Function GetKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer
Public Function IsKeyPressed(nKey As KeyCodeConstants) As Boolean
IsKeyPressed = GetKeyState(nKey) And &H8000
End Function
Private Sub Command1_Click()
If IsKeyPressed(KeyCodeConstants.vbKeyControl) Then
Debug.Print "Crtl 键同时按下了"
End If
If IsKeyPressed(KeyCodeConstants.vbKeyShift) Then
Debug.Print "Shift 键同时按下了"
End If
If IsKeyPressed(KeyCodeConstants.vbKeyMenu) Then
Debug.Print "Alt 键同时按下了"
End If
End Sub