weltensturm
weltensturm

Reputation: 2162

Win32 send sync events to other process

I am trying to write a program that allows me to move the camera in Dota 2 more intuitively. While holding space it simulates the middle mouse button, and when the cursor reaches the screen border it jumps back to the center. Centering the cursor looks like this (simplified):

PostMessage(w, WM_KEYUP, VK_MBUTTON, 0);
PostMessage(w, WM_MOUSEMOVE, 0, MAKELPARAM(screenWidth/2, screenHeight/2));
SetCursorPos(screenHeight/2, screenHeight/2)
PostMessage(w, WM_KEYDOWN, VK_MBUTTON, 0);

w is the window handle of Dota 2. The problem is that when this occurs, Dota still thinks the button is down, and so the camera jumps. I made it work partially by simulating key events with SendInput instead of sending messages directly, but that required a pause of 10ms between events and that is not what I want. Is there a way to see whether a message has been processed by another process?

Upvotes: 0

Views: 348

Answers (2)

Ben Voigt
Ben Voigt

Reputation: 283614

Games usually use DirectInput for mouse input, which will give them the true state of the mouse button. GetAsyncKeyState also will check the actual mouse button state.

Your messages won't have much (or any) effect if the game is using other mouse processing mechanisms.

You can try using SendInput instead, which changes some of the internal states which Windows reports to applications.

Upvotes: 1

ScottMcP-MVP
ScottMcP-MVP

Reputation: 10415

SendMessage (and SendMessageTimeout) indicate in their return value whether or not the message has been processed.

Upvotes: 0

Related Questions