Search code examples
cwindowsgoogle-chromenpapi

Using Windows raw_input in NPAPI windowed plugin in Chrome


I have an application which is working fine standalone. It handles all its keyboard/mouse input using raw input. When switching to NPAPI client windowed plugin, I receive inputs via WM_KEYDOWN for keyboard, whereas they're supposed to be disabled by my setup, and worse I do NOT receive any raw input WM_INPUT event for keyboard. Everything else is working, including D3D9 rendering in the window.

Here's how I setup the window roughly (it's quite lengthy):

...
SetWindowLongPtr(Application_hWnd, GWL_WNDPROC, (LONG_PTR)&Application_WndProc);
...

DEV_BROADCAST_DEVICEINTERFACE notificationFilter;
GUID hid = { 0 };
RAWINPUTDEVICE rid[4] = { 0 };

rid[1].usUsagePage = 0x01; // HID_USAGE_PAGE_GENERIC (in WDK)
rid[1].usUsage = 0x06; // HID_USAGE_GENERIC_KEYBOARD (in WDK)
rid[1].dwFlags = RIDEV_NOLEGACY;//RIDEV_DEVNOTIFY;
rid[1].hwndTarget = Application_hWnd; // capture only for this window

RegisterRawInputDevices(rid, sizeof(rid) / sizeof(rid[0]), sizeof(rid[0]));
... other raw device detection and related HID stuff

Receiving:

case WM_INPUT:
{
     if (GET_RAWINPUT_CODE_WPARAM(wParam) == RIM_INPUT)
     {
            RAWINPUT raw = { 0 };
            UINT dwSize = sizeof(raw);

            if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, &raw, &dwSize, sizeof(RAWINPUTHEADER)) > 0)
            {
                switch (raw.header.dwType)
                {
                case RIM_TYPEKEYBOARD:
                    // never reaches here

Error checking is omitted here for clarity, but no error is reported anywhere. Yet it seems to have no effect for keyboard, but I do receive WM_INPUT for mouse.

Anyone has a successfully working raw input keyboard in NPAPI ?


Solution

  • I would try creating your own child HWND inside the one the browser gives you where you'll have more control of what is going on.