raw input handling (distinguishing secondary mouse

2019-09-18 09:21发布

问题:

I was writing some pices in winapi's raw input It seem to working though I am not sure how reliable (unfaliable) it is (and if it will be working on all systems machines etc, this is a bit worry)

also there appears many question, the one is

I would like to use my first (I mean normal/base mouse) in old way, it is processint WM_MOUSEMOVE etc and moving arrow cursor, only the secondary mouse I need processing by raw_input (primary can stay untouched by rawinput), the problem is

1) how can i be sure which mouse detected by rawinput is the secondary?

2) the second mouse moves also my arrow -cursor, if I disable it by RIDEV_NOLEGACY then both are not moving cursor (it bacame hourglass) and it is wrong too

think maybe i should setup it a bit differently my setrup rawinput function is like

    void SetupRawInput()
    {

    static RAWINPUTDEVICE Rid[1];

    Rid[0].usUsagePage = 0x01;
    Rid[0].usUsage = 0x02;
    Rid[0].dwFlags = 0;     //   Rid[0].dwFlags =  RIDEV_NOLEGACY;   /
    Rid[0].hwndTarget = NULL;

    int r = RegisterRawInputDevices( Rid, 1, sizeof(Rid[0]) );

    if (!r)  ERROR_EXIT("raw input register fail");

    }

how to resolve this issueas andmake it work? tnx

回答1:

I don't know if my approach is the best one, or not, but this is how I do it for the first item in your question:

When I process WM_INPUT using GetRawInputData(...), I check to see if the device handle passed back by the RAWINPUTHEADER structure (contained within the RAWINPUT structure returned from the function) is the same as the device I want to use. If it is not, then I simply don't bother sending back data, if it is, I then process the RAWINPUTMOUSE data returned in the RAWINPUT struct.

And if you're wondering how to get the list of devices, you can use GetRawInputDeviceList(...), which will return the device handles of the mice you're trying to work with.

As I said, this may not be the best way, but I have confirmed that it does work for my purposes. I also do this for my keyboard raw input data as well.

As for item #2, it seems likely that it affects both mice because Windows has exclusive access to the mice, so you can't register one specific mouse without registering them all with the same flags. But someone with more knowledge than I could probably give a better explanation.