无法正确模拟动作。 c#中的SendMessage(间谍++)

时间:2012-05-04 07:02:51

标签: c# .net winapi sendmessage spy++

我在游戏过程中模拟了这个动作: - mouse_down - mouse_move - mouse_up

当我手动执行时,这是spy ++输出: enter image description here

MOUSE_DOWN:

enter image description here

MOUSE_MOVE:

enter image description here

MOUSE_UP:

enter image description here

所以我试图用下面的代码来模拟,开始x,y:(618,392)最终x,y:(618,432)但是它不起作用。

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)

这是使用代码后的间谍++输出:

enter image description here

我真的不知道为什么它不起作用。我一直用这种方式模拟键一段时间,动作如:ctrl + q,鼠标点击等等都没有任何问题。更重要的是,它为我工作,但只有一次。我卡在这里。谢谢你的帮助:)

1 个答案:

答案 0 :(得分:2)

您无法使用WM_LBUTTONDOWN功能发送鼠标消息(例如WM_MOUSEMOVESendMessage)来模拟鼠标输入。

是的,当您使用Spy ++监控消息时,看起来就像看起来那样,但there's a lot more going on behind the scenes

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

[DllImport("user32.dll", SetLastError = true)]
static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);