Search code examples
cwinapimouseeventuser-datasendinput

How to use dwExtraInfo with SendInput


I'm using ::SendInput to send a mouse click event:

void LeftDown (LONG x_cord, LONG y_cord)
{  
    INPUT    Input={0};
    // left down 
    Input.type = INPUT_MOUSE;
    Input.mi.dwFlags  = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN;
    Input.mi.dx = x_cord;
    Input.mi.dy = y_cord;
    Input.mi.dwExtraInfo = 0x12345;   //Is this how to use it?
    ::SendInput(1,&Input,sizeof(INPUT));
}

I want to set the dwExtraInfo to some self defined value and extract it in the WndProc at the target application. Then (for example) I will ignore that click if the dwExtraInfo is set to some specific value:

LRESULT CALLBACK OSRWindow::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ 
    if(message == WM_LBUTTONDOWN)
    {          
        if(GetMessageExtraInfo() == 0x12345)     //Is this how to use it?
            //ignore
        else
            //do something
    }
}

Is this naive way is the proper way to use dwExtraInfo or is there a better practice? Thanks!


Solution

  • The documentation says:

    dwExtraInfo

    An additional value associated with the mouse event. An application calls GetMessageExtraInfo to obtain this extra information.

    So yes, use it just as you have shown it in your question.