vba 每 30 分钟移动一次鼠标指针

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44368750/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 12:41:32  来源:igfitidea点击:

Move the mouse pointer every 30 minutes

excelvba

提问by Alexander

I want my mouse pointer to move automatically every 30 minutes.
I am writing the code in Excel VBA.
I tried https://support.microsoft.com/en-us/help/152969/visual-basic-procedure-to-get-set-cursor-positionbut it doesn't work.

我希望我的鼠标指针每 30 分钟自动移动一次。
我正在用 Excel VBA 编写代码。
我试过https://support.microsoft.com/en-us/help/152969/visual-basic-procedure-to-get-set-cursor-position但它不起作用。

回答by Alexander

Create new module with following code:

使用以下代码创建新模块:

Private dtmNext As Date
Private Type POINTAPI
    x As Long
    y As Long
End Type

Private Declare Function GetCursorPos Lib "user32" (Point As POINTAPI) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Integer, ByVal y As Integer) As Long

Sub Move_Cursor()
    Dim Hold As POINTAPI
    GetCursorPos Hold
    SetCursorPos Hold.x + 30, Hold.y
    dtmNext = DateAdd("n", 30, Now)
    Application.OnTime dtmNext, "Move_Cursor"
End Sub

Sub Stop_Cursor()
    Application.OnTime dtmNext, "Move_Cursor", , False
End Sub

Call Move_Cursor()to start moving the cursor every 30 minuts. To stop the automatic motion, use

Move_Cursor()每 30 分钟调用一次以开始移动光标。要停止自动运动,请使用

Application.OnTime dtmNext, "Move_Cursor", , False