Question

I am writing a small program to emulate the mouse with my Xbox 360 controller. I have successfully implemented movement of the cursor but am having difficulty with clicks.

Here is a snippet of my code:

while (msg.message != WM_QUIT) {
    if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    } else {

        ...           

        if (state.Gamepad.wButtons & XINPUT_GAMEPAD_A) {
            PostMessage(HWND_BROADCAST, WM_LBUTTONDOWN, 0, MAKEWORD(new_x, new_y));
        }

        ...       
    }
}

I'm not 100% sure this is the right approach but I'm trying to send the WM_LBUTTONDOWN message to all top-level windows when the A button is pressed. But when I place the mouse over say, a button and press A, the button flashes as if it was clicked but then nothing happens.

If anyone can point me in the right direction or offer an alternative way to do this I'd be very grateful!

Was it helpful?

Solution

I think, instead of PostMessage, you'd rather use the mouse_event API or even SendInput. It allows you to synthesise mouse events on a more abstract level.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top