连按两下ctrl呼出界面,这个怎么写
网上找了一段代码 但是不知道怎么实现连按两下ctrl呼出界面?
参考代码
判断按键被快速的按下了两次
原理:判断2次按键的时间差。
但是由于系统提供的时间不支持到毫秒,所以用了API函数来读取。
Private Declare Sub GetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Const 时间间隔 As Long = 500 '毫秒
Dim TW As SYSTEMTIME
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Static 上次时间 As Long
Static 上次按键 As Integer
'读当前时间
Call GetLocalTime(TW)
'判断时差
If TW.wSecond * 1000& + TW.wMilliseconds - 上次时间 < 时间间隔 And KeyCode = 上次按键 Then
MsgBox "按了2下!!"
End If
上次时间 = TW.wSecond * 1000& + TW.wMilliseconds
上次按键 = KeyCode
End Sub
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Const 时间间隔 As Long = 500 '毫秒
Private 上次时间 As Long
Private 上次按键 As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim lKeyTime As Long
lKeyTime = GetTickCount()
If (KeyCode = vbKeyControl) Then
If (vbKeyControl = 上次按键 And lKeyTime - 上次时间 < 时间间隔) Then
MsgBox "连续按下两次 Ctrl键", vbInformation
End If
End If
上次时间 = lKeyTime
上次按键 = KeyCode
End Sub
Private Sub Form_Load()
KeyPreview = True
上次时间 = -1
上次按键 = -1
End Sub