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;
rid.usUsagePage = 0x01;
rid.usUsage = 0x06;
rid.dwFlags = RIDEV_REMOVE;
rid.hwndTarget = IntPtr.Zero;
if (!RegisterRawInputDevices(rid, (uint)rid.Length, (uint)Marshal.SizeOf(rid)))
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.