定时移动鼠标点击鼠标,防止电脑息屏的vba脚本

Type POINTAPI ' This holds the logical cursor information
    Dim x As Long
    Dim y As Long
End Type


Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function SetCursorPos Lib "user32" (Byval x as long, Byval y as long) As Long
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByValdwMilliseconds As LongLong)
private static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);

const int MOUSEEVENTF_LEFTDOWN = 0x0002   ' 模拟鼠标左键按下
const int MOUSEEVENTF_LEFTUP = 0x0004   ' 模拟鼠标左键抬起

'delay for 1s, 2s ....
'input: 1,2,3.....
Sub Delay_Sec(Byval sec as Integer)
    For i=1 to sec * 10
        DoEvents
        Sleep 100
    Next
End Sub

'sleep milliseconds
Sub Delay_MilliSec(Byval milli_sec as Integer)
    For i=1 to milli_sec step 100
        DoEvents
        Sleep 100
    Next
End Sub

Function Get_Rand()
    Dim a as integer
    Dim b as integer
    
    a = Rnd() * 100
    b = b Mod 30
    
    Get_Rand = b
End Function

Sub mouse_helper()
    Dim i as integer
    Dim cur_pos as POINTAPI
    Dim rnd as integer
    
    For i = 1 to 10000
        GetCursorPos cur_pos
        SetCursorPos cur_pos.x + 2, cur_pos.y + 1
        
        Delay_MilliSec 100   'sleep For 100ms
        mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
        Delay_MilliSec 500   'sleep For 500ms
        mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0

        rnd = Get_Rand
        Delay_Sec rnd
        Debug.Print "delay For " & rnd & " seconds"
    Next
End Sub
  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值