Mouse Input in WinAPI

mouse buttons have virtual keycodes (VK_LBUTTON, etc.). Can I use them instead of using the mouse messages? If yes, Do I need to send the mouse messages to DefWindowProc() or not? Does it matter?
You could send some mouse events by mouse_event. View MSDN for details.
I don't need mouse_event. I need real input from the mouse, not events triggered by software.
The closest you'll get is SendInput(), from which mouse_event() is deprecated.
Ummm...what? I DON'T need to trigger mouse events. I'm asking about REAL INPUT from the mouse.
Last edited on
Software can only simulate mouse events, "real" input is where you use your finger and physically press the mouse.
...That's what he wants to do. Simulate mouse input (i.e. send VK_LBUTTON somewhere and the computer does something)
I'm confused. Are you asking to send mouse input to another application, or are you asking how to receive it?

If you want to receive it, in DefWindowProc's switch() just put case WM_LBUTTONDOWN, WM_RBUTTONDOWN or WM_MBUTTONDOWN (left, right, middle button in that order). Then you can use WM_xBUTTONUP for when they unclick.

e.g, the WindowProcedure from a drawing app I wrote a couple of months ago (with a large amount of help from someone on this forum called "Hammurabi):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// This function is called by DispatchMessage()
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wp, LPARAM lp) {
switch (message) {
    case WM_MOUSEMOVE: // If the mouse moves across the screen
         wmMouseMove(hwnd, wp, lp);
         break;
    case WM_LBUTTONDOWN: // Left button down
         wmLButtonDown(hwnd, wp, lp);
         break;
    case WM_LBUTTONUP: // Left button up
         wmLButtonUp(hwnd, wp, lp);
         break;
    case WM_DESTROY:
         PostQuitMessage(0);       // Send WM_QUIT
         break;
    case WM_KEYDOWN: // Catch key presses
        wmKeyDown(hwnd, wp, lp);
        break;
    default:
         return DefWindowProc(hwnd, message, wp, lp);
         }

return 0;
}


If you're looking to send input to another application, it can only be done with SendInput(). I asked this very same question once but no-one knew a way of doing it other than SendInput(), which didn't work for me for some reason. Not even because Vista (>:[) doesn't allow it; it wouldn't compile.

Anyway, try SendInput() or WM_xBUTTONDOWN/UP, depending on what question you're asking.
Last edited on
Topic archived. No new replies allowed.