【问题标题】:Mouse position values for SendInputSendInput 的鼠标位置值
【发布时间】:2014-12-05 16:59:52
【问题描述】:

我正在开发一个 C# 应用程序来使用在 Winuser.h 中声明的 SendInput 来模拟鼠标移动。 我对 SendInput 的调用工作正常,我可以在屏幕上移动鼠标。

然后我尝试使用以下方法记录用户鼠标移动:

    [DllImport("user32.dll")]
    public static extern bool GetCursorPos(ref POINT lpPoint);

然后将鼠标点传递给 SendInput。我注意到 GetCursorPos 获得的鼠标值与 SendInput 实际定位鼠标的位置之间存在差异。例如,鼠标 x 位置 1300(屏幕最右侧)对应于使用 SendInput 的鼠标定位在屏幕左侧附近。

GetCursorPos 得到的 POINT 数据与 SendInput 使用的坐标系有什么关系。

谢谢。

兰斯

【问题讨论】:

  • 您忽略了显示任何代码。我们不知道您如何调用 SendInput。也许你弄错了。我们看不到您是否检查过错误。也许你可以展示一个完整的程序来演示这个问题。
  • 两个 api 调用都没有问题,所以我没有费心发布代码。我已经找到了解决方案,GetCursorPos 返回屏幕坐标,sendinput 需要绝对坐标。这篇文章包含必要的转换:stackoverflow.com/questions/8021954/…

标签: c# mouse sendinput


【解决方案1】:

如以下问题所述:

SendInput doesn't perform click mouse button unless I move cursor

GetCursorPos返回的屏幕坐标需要转换成绝对坐标传递给SendInput:

dx =  (x * 65536) / GetSystemMetrics(SystemMetric.SM_CXSCREEN);
dy = (y * 65536) / GetSystemMetrics(SystemMetric.SM_CYSCREEN);

兰斯。

【讨论】:

    猜你喜欢
    • 2018-07-13
    • 1970-01-01
    • 2015-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多