繁体   English   中英

SendInput鼠标时间

[英]SendInput mouse time

因此,基本上我想做的就是将鼠标平稳地移动到中心。 我在这里拥有的功能正常,但是它将光标立即传送到中心。

另外,如果将input.mi.time设置为大于0的值,则会使PC进入睡眠状态。 谁能进一步解释它的作用? 文档并没有真正为我澄清。

#include <iostream>
#include <Windows.h>

int screenWidth;
int screenHeight;

void moveMouse(int x, int y)
{
    POINT mouseCoords;
    GetCursorPos(&mouseCoords);

    INPUT input;
    input.type = INPUT_MOUSE;
    input.mi.dwFlags = MOUSEEVENTF_MOVE;
    input.mi.dwExtraInfo = NULL;
    input.mi.mouseData = NULL;
    input.mi.dx = -mouseCoords.x + x;
    input.mi.dy = -mouseCoords.y + y;
    input.mi.time = NULL;

    SendInput(1, &input, sizeof(INPUT));
}

void main()
{
    screenWidth = GetSystemMetrics(SM_CXSCREEN);
    screenHeight = GetSystemMetrics(SM_CYSCREEN);
    int middleOfScreenX = screenWidth / 2;
    int middleOfScreenY = screenHeight / 2;

    moveMouse(middleOfScreenX, middleOfScreenY);
}

您遇到的问题与Raymond Chen在2012年的帖子中描述的完全一样:

当您使用SendInput合成输入时,您也在合成时间戳 (重点是我的):

客户在使用SendInput函数模拟用于自动测试目的的拖放操作时报告了问题。

是的,所有事件都立即发生,因为您一次提交了所有事件。

MOUSEINPUT结构中的time字段不用于引入回放延迟

解决方案也在发布中:

如果要发生三个输入事件,它们之间的延迟为500ms,则需要调用3次SendInput,两次调用之间的延迟为500ms。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM