鼠标点击/移动模拟在一个“特定窗口”上。

huangapple go评论65阅读模式
英文:

Mouse click/move simulation on a "specific window"

问题

这是我代码的一部分,用于实现鼠标模拟:

SendMessage(winHandle, WM_MOUSEMOVE, 0, MAKELPARAM(0, 0));
SendMessage(winHandle, WM_LBUTTONDOWN, 0, 0);
SendMessage(winHandle, WM_LBUTTONUP, 0, 0);

正如你所见,我试图让鼠标光标移动到指定窗口的坐标点 (0, 0) 并执行一次点击。但出于某种原因,光标根本不动,而只是在当前位置进行点击。我该如何解决这个问题?

英文:

This is the part of my code that is supposed to implement the mouse simulation:

SendMessage(winHandle, WM_MOUSEMOVE, 0, MAKELPARAM(0, 0));
SendMessage(winHandle, WM_LBUTTONDOWN, 0, 0);
SendMessage(winHandle, WM_LBUTTONUP, 0, 0);

As you can see, i'm trying to make the mouse's cursor move to a the point (0, 0) of the specified window and perform a single click. But for some reason, the cursor doesn't move at all, and it just clicks on wherever it's currently in.
How can i fix that?

答案1

得分: 2

WM_MOUSEMOVE实际上不会移动光标,它只是通知窗口发生了移动。要实际移动光标,请使用SetCursorPos()SendInput()。可以使用ClientToScreen()MapWindowPoints()将所需的客户端坐标转换为屏幕坐标,然后进行移动。

英文:

WM_MOUSEMOVE doesn't actually move the cursor, it just notifies the window that a movement had occurred. To actually move the cursor, use SetCursorPos() or SendInput() instead. Use ClientToScreen() or MapWindowPoints() to convert the desired client coordinates into screen coordinates to then move to.

huangapple
  • 本文由 发表于 2023年1月8日 22:54:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75048743.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定