c - 鼠标随 SendInput 飘走
问题描述
当我收到坐标时,GetCursorPos
我需要将它们设置回坐标。
下面是一个代码示例(第一个场景),展示了如何实现这一目标。
for(;;)
{
// get cursor position
POINT Point;
GetCursorPos(&Point);
// send mouse input
SetCursorPos(Point.x, Point.y);
// sleep
usleep(15000);
}
上述方法使用SetCursorPos
,我不打算使用。下面的代码示例(第 2 种情况)应该以相同的方式使用INPUT
and SendInput
,但事实并非如此(更多下文)。
for(;;)
{
// get cursor position
POINT Point;
GetCursorPos(&Point);
// configure mouse input
INPUT Input;
Input.type = INPUT_MOUSE; // mouse input type
Input.mi.dx = (Point.x * 65535) / 2560; // normalized x coordinate
Input.mi.dy = (Point.y * 65535) / 1440; // normalized y coordinate
Input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE; // move absolute
Input.mi.time = 0; // let system decide
Input.mi.dwExtraInfo = 0;
// send mouse input
SendInput(1, &Input, sizeof(INPUT));
// sleep
usleep(15000);
}
我期望在这两种情况下会发生什么:
- 鼠标移动而不会被奇怪地推向任何方向
真正发生的事情:
- 第一种情况:期望得到满足
- 第二种情况:鼠标(一次 1 个像素)向中间顶部漂移(注)
(注)我使用双显示器设置,并排排列。两台显示器的分辨率均为 2560 x 1440。中间顶部是右侧显示器的左上角。
这(在我看来)清楚地表明我在使用SendInput
. 我怎样才能消除这种奇怪的行为?
解决方案
推荐阅读
- performance - SAPUI5:网格表:列调整大小性能问题
- firebase - 使用 StreamProvder 获取用户身份验证更改
- firebase - 如何解决谷歌操作控制台上的意图问题
- lm - R:lm写错R2总结
- sql - [xx:xx] 真的告诉我错误在哪里吗?(谷歌大查询)
- python - 熊猫在 groupby 上的滚动平均值
- reactjs - 如何运行覆盖一个文件的 Jest 测试
- java - 无法在 Yarn 集群模式下将 Query 传递给 java spark 程序
- r - 如何根据 r 中的多个条件按组过滤案例?
- java - 使用 spring boot 暴露 Rpc Style WS