0

I've got a problem with simulating in game's process this action: - mouse_down - mouse_move - mouse_up

When I do it manually, that's the spy++ output: enter image description here

mouse_down:

enter image description here

mouse_move:

enter image description here

mouse_up:

enter image description here

So I've tried to simulate that with below code start x,y: (618,392) final x,y: (618,432) but It's not working.

uint Iparm = makeDWord((ushort)x, (ushort)y);
IntPtr xd = new IntPtr(Iparm);
uint Iparm2 = makeDWord((ushort)x2, (ushort)y2);
IntPtr xd2 = new IntPtr(Iparm2);

SendMessage(UltraBot.p, (uint)0x201, (IntPtr)0x1, xd); // down button (start x,y)
SendMessage(UltraBot.p, (uint)0x200, (IntPtr)0x1, xd2); // move (final x,y)
SendMessage(UltraBot.p, (uint)0x202, (IntPtr)0x0, xd2); // up button (final x,y)

Here's the spy++ output after using the code:

enter image description here

I don't really know why it's not working. I've been using this way to simulate keys for some time, actions like: ctrl+q, mouse clicks and so werent any problem. What's more, IT WORKED FOR ME ONCE, but just once. I've stuck in here. Thanks for any help :)

4

1 回答 1

2

您不能通过使用该函数发送鼠标消息(例如WM_LBUTTONDOWNWM_MOUSEMOVE)来模拟鼠标输入。SendMessage

是的,当您使用 Spy++ 监控消息时,看起来就是这样,但幕后还有很多事情要做

要正确模拟鼠标或键盘输入,您需要使用SendInput函数. 从 C# 调用它的 P/Invoke 声明如下所示:

[DllImport("user32.dll", SetLastError = true)]
static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
于 2012-05-04T07:30:41.440 回答