Jump to content
  • Advertisement
Sign in to follow this  
abort

Raw Input

This topic is 3609 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there guys, I was wondering... is there any way to make another thread handle the messages for WM_INPUT (raw input)... it's quite lame to pass it on through the window proc. So basically just like Direct Input does but without the overhead (more about how that works here. I have been looking on msdn / google for a while but couldn't really find much, maybe someone has a suggestion. Another thing i would like to know... is there any benefit of buffering raw input when I only use raw input for coordinates? I can't find any documentation about this, but I guess buffering is only useful for keyboard buttons. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
Yes I do this in my game engine, here is the way I do it:



LRESULT CALLBACK GetInputs( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
switch( message )
{
case WM_INPUT:
{
UINT dwSize;
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &dwSize, sizeof(RAWINPUTHEADER));
LPBYTE lpb = new BYTE[dwSize];
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER));
RAWINPUT* raw = (RAWINPUT*)lpb;
if (raw->header.dwType == RIM_TYPEKEYBOARD)
{
...
}
else if (raw->header.dwType == RIM_TYPEMOUSE)
{
...
}
delete[] lpb;
break;
}
}
return DefWindowProc( hWnd, message, wParam, lParam );
}




int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow )
{
WNDCLASSEX wcex;
ZeroMemory( &wcex, sizeof( wcex ) );
wcex.cbSize = sizeof( WNDCLASSEX );
wcex.lpfnWndProc = GetInputs;
wcex.lpszClassName = "Input";
RegisterClassEx( &wcex );
HWND hWnd = CreateWindowEx( NULL, "Input", "Input", NULL, NULL, NULL, NULL, NULL, HWND_MESSAGE, NULL, NULL, NULL );
UnregisterClass( "Input", NULL );
RAWINPUTDEVICE Rid[2];
Rid[0].usUsagePage = 0x01;
Rid[0].usUsage = 0x02;
Rid[0].dwFlags = RIDEV_INPUTSINK;
Rid[0].hwndTarget = hWnd;
Rid[1].usUsagePage = 0x01;
Rid[1].usUsage = 0x06;
Rid[1].dwFlags = RIDEV_INPUTSINK;
Rid[1].hwndTarget = hWnd;
RegisterRawInputDevices(Rid, 2, sizeof(Rid[0]));

...

}



If this was helpful then I'd appreciate + rating! [wink]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!