I've registered my raw input devices successfully but Windows doesn't send me the WM_INPUT message when I press keys or do things with the mouse. I am using an event hook to get the messages since I'm using SDL and it receives other messages fine.
This is the code I have to register my raw input devices:
bool CInput::Init( void )
{
RAWINPUTDEVICE Rid[2];
// Keyboard
Rid[0].usUsagePage = 1;
Rid[0].usUsage = 6;
Rid[0].dwFlags = 0;
Rid[0].hwndTarget = NULL;
// Mouse
Rid[1].usUsagePage = 1;
Rid[1].usUsage = 2;
Rid[1].dwFlags = 0;
Rid[1].hwndTarget = NULL;
if( !RegisterRawInputDevices( Rid, 2, sizeof( RAWINPUTDEVICE ) ) )
return false;
return true;
}
And this is my message hook. Note that if windows send any other type of message this function gets called.
LRESULT HookProcedure( int nCode, WPARAM wParam, LPARAM lParam )
{
//Get the message info.
CWPSTRUCT *info = (CWPSTRUCT*)lParam;
//Use the raw input data.
if( info->message == WM_INPUT )
{
//Don't use the message if the application was in the background.
if( info->wParam == RIM_INPUTSINK )
return CallNextHookEx( NULL, nCode, wParam, lParam );
input->InputRecieved( info->lParam );
}
return CallNextHookEx( NULL, nCode, wParam, lParam );
}
This is how I set the hook.
sys_hook = SetWindowsHookEx( WH_CALLWNDPROC, (HOOKPROC)HookProcedure, NULL, GetCurrentThreadId( ) );