gpt4 book ai didi

c++ - SendInput鼠标时间

转载 作者:行者123 更新时间:2023-11-30 03:26:04 27 4
gpt4 key购买 nike

所以基本上我要做的是将我的鼠标平滑地移动到中心。我这里的东西工作正常,但它会立即将光标传送到中心。

此外,如果我将 input.mi.time 设置为大于 0 的值,它会使我的 PC 进入休眠状态。任何人都可以解释一下它的作用吗? documentation并没有真正为我澄清。

#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 年的帖子中描述的完全相同:

When you synthesize input with SendInput, you are also synthesizing the timestamp (重点是我的):

A customer was reporting a problem when they used the Send­Input function to simulate a drag/drop operation for automated testing purposes.

Well, yeah, all the events occur immediately because you submitted them all at once.

The time field in the MOUSE­INPUT structure is not for introducing delays in playback.

解决方案也在帖子中:

If you want three input events to take place with a 500ms delay between them, then you need to call Send­Input three times, with a 500ms delay between the calls.

关于c++ - SendInput鼠标时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48591918/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com