网上找了一段代码 但是不知道怎么实现连按两下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 SYSTEMTIMEPrivate 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
参考代码
判断按键被快速的按下了两次原理:判断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 SYSTEMTIMEPrivate 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
解决方案 »
- 100分求救 vb 如何对N组数据进行分析,找出每组数据的规律?
- webbrowser 出现 access denied 错误
- 我相信可以实现的!
- 怎么样把MsflexGrid控件里显示的数据全部打印出来
- VB中怎样实现如QQ上按CTRL+ALT+X把程序从后台唤到前台的功能
- 请问各位,VB可以用结构体数组做为参数吗?
- 请教下GetOpenFileNameW文件多选的问题
- 怎样用经纬度计算日出日落的时间
- 自学好还是培训学
- 有的时候看到网页上精美的 Flash 动画想收藏到自己的硬盘上来,却苦于无从下手。如果你也遇到过有这个问题那就试试这个软件吧:GetFlash
- 求助vb.net如何自定义文件类型读取文件内容
- 如何判断数组中是否有某元素
这个代码,有一个问题是,按下后不放开,会造成“连续按键”的结果。
要防止这个问题,就还要在 KeyUp 事件中处理。
Option ExplicitPrivate Declare Function GetTickCount Lib "kernel32" () As LongPrivate Const 时间间隔 As Long = 500 '毫秒Private 上次时间 As Long
Private 上次按键 As IntegerPrivate 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 SubPrivate Sub Form_Load()
KeyPreview = True
上次时间 = -1
上次按键 = -1
End Sub