我是校园拨号网
是按时间计时,经常在看电影时忘了断网!希望高人闲暇之余帮忙写个小软件
实现功能:
1,软件运行的时候,如果**分钟不动鼠标就自动断网
2,断网前设置10秒倒计时(倒计时可选“是”或“否”) 请发我邮箱哈
[email protected]

解决方案 »

  1.   

    随便写了点,倒计时什么的自己完善就行,大致这个思路就可以Option ExplicitPrivate Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Private Declare Function GetCursorPos& Lib "user32" (lpPoint As PointAPI)
    Private Type PointAPI
        X As Long: Y As Long
    End Type
    Dim ctTimer As SinglePrivate Sub Form_Load()
       Timer1.Enabled = True: Timer1.Interval = 100
    End SubPrivate Sub Timer1_Timer()
       Dim T As Single
       T = Format(Timer - ctTimer, "0.0")
       If KeyOrMouse() Then T = 0: ctTimer = Timer
       Me.Caption = "鼠标和键盘未动时间:" & T & " 秒"
       '//断网
       Dim t0 As Single
       t0 = 100 - T
       If t0 < 10 Then
            Label1.Caption = "离断网还有" & t0 & "秒"
            If t0 <= 0 Then Shell "rasdial.exe /Disconnect", vbHide '断网
       End If
    End Sub
    Private Function KeyOrMouse() As Boolean
       Static x0 As Long, y0 As Long
       Dim nMouse As PointAPI, I As Long, dl As Long
       
       '检测鼠标  是否移动
       Call GetCursorPos(nMouse) '获取当前鼠标位置
       If x0 <> nMouse.X Or y0 <> nMouse.Y Then KeyOrMouse = True
       x0 = nMouse.X: y0 = nMouse.Y
       If KeyOrMouse Then Exit Function
       
       '检测键盘  是否按动
       For I = 0 To 255
          dl = GetAsyncKeyState(I)
          If dl <> 0 Then KeyOrMouse = True: Exit Function
       Next
    End Function