none
unregister Keyboard device using RIDEV_REMOVE not working

    Question

  • Hi there,

    I have implemented the raw input method for handling the keyboard inputs for an external application. The code is working absolutely fine and I am able to handle all the events but there is a button in this external application which opens an outlook new mail window as a modal dialog box(same as the Send->Email functionality in MS-Excel 2007).

    As soon as this mail window modal dialog opens, I am not able to type anything in this mail window, not even the address in the address bar.

    On deep diagnosis, I found that the raw input method is consuming all the key data and don't let it pass to the outlook window.

    To get rid of this problem, I have overridden the WndProc() method and tried to unregister the keyboard on the deactivation of application's main window(because whenever modal dialog opens, the application's main window deactivates). The code for unregistering keyboard that I wrote is as follows:

     public void UnRegisterKeyboardDevice()
            {
                uint i = 0;                      
                RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[1];
                rid[0].usUsagePage = 0x01;
                rid[0].usUsage = 0x06;
                rid[0].dwFlags = RIDEV_REMOVE;
                rid[0].hwndTarget = IntPtr.Zero;
    
                if (!RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid[0])))
                {
                    throw new ApplicationException("Failed to register raw input device(s).");
                }           
            }

    But This code is not working for the first time i.e. whenever I click on the button, It opens the outlook modal mail window but I am not able to type anything(same as earlier) but If I close this window and again click on the button then again a new mail window opens and this time I am able to type anything and everything required.

    In simple words, the code above is not working for the first time but the next time it works fine.

    I am using Visual studio 2010 ultimate on Windows 7 environment.

    I have tried to debug the code but didn't received any errors or exceptions while debugging.

    But while debugging I found that sometimes while debugging, it works for the first time also.

    I hope the problem statement is clear.

    Please Help.

    Thanks

    Monday, December 02, 2013 4:19 AM