1,502
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Dim StartTime As Date
Dim KeyAsc As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If (KeyCode <> KeyAsc) Or StartTime = 0 Then
StartTime = Now()
KeyAsc = KeyCode
Debug.Print "S", StartTime
End If
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Dim PassTime As Long
Dim EndTime As Date
If KeyCode = KeyAsc Then
EndTime = Now()
Debug.Print "E", EndTime
PassTime = DateDiff("s", StartTime, EndTime)
MsgBox "按键经过" & PassTime & "秒"
StartTime = 0
End If
End Sub
Dim StartTime As Date
Dim KeyAsc As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode <> KeyAsc Then
StartTime = Now()
KeyAsc = KeyCode
Debug.Print "S", KeyCode, StartTime
End If
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Dim PassTime As Long
Dim EndTime As Date
If KeyCode = KeyAsc Then
EndTime = Now()
Debug.Print "E", KeyCode, EndTime
PassTime = DateDiff("s", StartTime, EndTime)
KeyAsc = 0
Debug.Print "按键经过" & PassTime & "秒"
End If
End Sub
Option Explicit
Dim StartTime As Date
Dim KeyAsc As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode <> KeyAsc Then
StartTime = Now()
KeyAsc = KeyCode
Debug.Print "S", StartTime
End If
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Dim PassTime As Long
Dim EndTime As Date
If KeyCode = KeyAsc Then
EndTime = Now()
Debug.Print "E", EndTime
PassTime = DateDiff("s", StartTime, EndTime)
MsgBox "按键经过" & PassTime & "秒"
End If
End Sub