Domanda

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 :)

È stato utile?

Soluzione

You cannot simulate mouse input by sending mouse messages (such as WM_LBUTTONDOWN and WM_MOUSEMOVE) using the SendMessage function.

Yes, that's what it looks like is happening when you monitor the messages with Spy++, but there's a lot more going on behind the scenes.

To simulate mouse or keyboard input properly, you need to use the SendInput function. The P/Invoke declaration to call it from C# looks like this:

[DllImport("user32.dll", SetLastError = true)]
static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top