VB检测鼠标是否移动

来源:百度知道 编辑:UC知道 时间:2024/06/16 21:51:32
要求:运行某个程序,程序开始时自动倒计时,并在标题栏(或界面上)显示倒计时20秒,如果到了0秒,就执行msgbox"OK"(程序中这个指令时连接网络,不过这命令不用写,我会写)。如果中途鼠标移动了,则,停止计时(归零或不归零都行)。

程序大意:开机自动运行,程序中开始倒计时,如果20s没有鼠标的操作,就连接网络,如果鼠标移动了,就停止计时。就可以操作界面了,界面上有播放音乐等按钮

【不要胡乱复制就发上来】
【如果回答对了,加分】
具体给出源码

你这是定时关机程序吧,上面的可以使用,具体错了没就不知道了!

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
formload时取一座标值
End Sub
20s时对比,只要一动座标值就会变化,

Private Declare Function GetCursorPos Lib "user32" (lpPoint As PointApi) As Long
Private Type PointApi
x As Long
y As Long
End Type
Dim a As PointApi
Dim b As PointApi
Private Sub Form_Load()
GetCursorPos a
Timer1.Enabled = True
Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()
Static i As Integer
GetCursorPos b
i = i + 1
If b.x <> a.x Or b.y <> a.y Or i >= 20 Then Print "停止": Timer1.Enabled = False
End Sub