Raw Input Alternative Keyboard Hook?

Quick question -

I read about keyboard hooks and suggested using Raw Input for this, but I did not find any example. For example, I use

RAWINPUTDEVICE rid[1];
rid[0].usUsagePage = 0x01;
rid[0].usUsage = 0x06;
rid[0].hwndTarget = hWnd;
rid[0].dwFlags = 0;
RegisterRawInputDevices(rid, 1, sizeof(rid[0]));

And catch WM_INPUT in its own application window, but not outside the application. Is this possible outside the application or do you need to use WH_KEYBOARD or WH_KEYBOARD_LL? MSDN did not make it clear whether Raw Input can be done globally.

EDIT: I know about Hooks, but I want to know if you can do this using Raw!

Greetings

+5
source share
4 answers

Windows - , , . (, ) . Windows, ​​ SetWindowsHookEx. , dll. MSDN.

0

MSDN , RIDEV_INPUTSINK, : " , , ."

, , .

+7

RAW INPUT . - DLL. WM_INPUT. : RAW INPUT

#include <Windows.h>

const USHORT HID_MOUSE    = 2;
const USHORT HID_KEYBOARD = 6;

bool HID_RegisterDevice(HWND hTarget, USHORT usage)
{
    RAWINPUTDEVICE hid;
    hid.usUsagePage = 1;
    hid.usUsage = usage;
    hid.dwFlags = RIDEV_DEVNOTIFY | RIDEV_INPUTSINK;
    hid.hwndTarget = hTarget;

    return !!RegisterRawInputDevices(&hid, 1, sizeof(RAWINPUTDEVICE));
}

void HID_UnregisterDevice(USHORT usage)
{
    RAWINPUTDEVICE hid;
    hid.usUsagePage = 1;
    hid.usUsage = usage;
    hid.dwFlags = RIDEV_REMOVE;
    hid.hwndTarget = NULL;

    RegisterRawInputDevices(&hid, 1, sizeof(RAWINPUTDEVICE));
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR cmd_line, int cmd_show)
{
    WNDCLASS wc;
    ...
    RegisterClass(&wc);

    HWND hwnd = CreateWindow(...);
    ...

    HID_RegisterDevice(hwnd, HID_KEYBOARD);
    HID_RegisterDevice(hwnd, HID_MOUSE);

    MSG msg;
    while(GetMessage(&msg, NULL, 0, 0))
    {
        ...
    }

    HID_UnregisterDevice(HID_MOUSE);
    HID_UnregisterDevice(HID_KEYBOARD);

    return (int) msg.wParam;
}
+1

, dll , .

0

All Articles