所以基本上,我要做的是把鼠标平稳地移到中心。我这里的功能很好,但是它可以将光标瞬间传送到中心。
另外,如果我将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);
}发布于 2018-02-02 23:00:17
你正经历着与2012年雷蒙德·陈( Raymond )在一篇文章中描述的完全相同的问题:
当您使用SendInput合成输入时,您也在合成时间戳。 (重点是我的):
一个客户在报告一个问题时,他们使用发送输入函数来模拟一个拖放操作,以实现自动化测试。 嗯,是的,所有的事件都会立即发生,因为你一次就把它们都提交了。 在
timeMOUSEINPUT结构中的字段并不用于在播放中引入延迟。
解决方案也在帖子中:
如果您希望在三个输入事件之间延迟500 to,则需要调用三次发送输入,并在呼叫之间延迟500 to。
https://stackoverflow.com/questions/48591918
复制相似问题