可以在每個物件的 MouseMove 事件 與 一個Timer 上作組合判斷
(需要一對 gX、gY 變數)
但其有個缺點 滑鼠一離開你的視窗程式 其滑鼠的移動 就不算數
此時就可用系統Hook方法
(但對初學者而言難理解了點...)
語法:
'timeGetTime()
'精度約1ms , 此式適用於大多數應用場合
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
'Dim CTime As Integer
Dim TempT As Long
Dim PreText As String
Dim gX As Single, gY As Single
Private Sub Form_Load()
PreText = Text1
'CTime = 10
TempT = timeGetTime
Timer1.Interval = 100
Timer1.Enabled = True
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If gX = X And gY = Y Then Exit Sub
gX = X: gY = Y
'CTime = 40
TempT = timeGetTime
If Timer1.Enabled = False Then
Text1 = PreText
Timer1.Enabled = True
End If
End Sub
Private Sub Timer1_Timer()
'CTime = CTime - 1
'Debug.Print CTime
'If CTime < 0 Then
If (timeGetTime - TempT) > 4000 Then
PreText = Text1
Text1 = Time
Timer1.Enabled = False
End If
End Sub
以上程式為求準確使用 timeGetTime
API函式
也可完全用 Timer 的計數準確度 (把上面的' 註解取消與 timeGetTime交換)
只是
VB 的 Timer 影響因素眾多
很容易不準確