Jump to content
  • Advertisement
Sign in to follow this  

HID Data From Raw Input

This topic is 4349 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

I'm trying to figure out all this raw input stuff to read data from my PS2 controller (hooked up with a PS2 to USB adapter) as well as the keyboard (which I don't need help with right now because I can get that off of MSDN). I can't figure out how to read the actual data. Using MSDN, this is what I came up with:
void Init(void)
{
	RAWINPUTDEVICE Rid[2];
        
	Rid[0].usUsagePage = 0x01; 
	Rid[0].usUsage = 0x04; 
	Rid[0].dwFlags = 0;
	Rid[0].hwndTarget = 0;

	Rid[1].usUsagePage = 0x01; 
	Rid[1].usUsage = 0x06; 
	Rid[1].dwFlags = 0;
	Rid[1].hwndTarget = 0;

	RegisterRawInputDevices(Rid, 2, sizeof(Rid[0]));
}


LRESULT HandleRawInput(HWND window, UINT msg, WPARAM wparam, LPARAM lparam)
{
	UINT size;
	GetRawInputData((HRAWINPUT)lparam, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER));
	LPBYTE lpb = new BYTE[size];
	if(lpb == NULL)
		return 0;
	
	if(GetRawInputData((HRAWINPUT)lparam, RID_INPUT, lpb, &size, sizeof(RAWINPUTHEADER)) != size)
		return 0;

	RAWINPUT* raw = (RAWINPUT*)lpb;

	if(raw->header.dwType == RIM_TYPEHID)
	{
	}
	else if(raw->header.dwType == RIM_TYPEKEYBOARD)
	{
	}

	delete[] lpb;
	return 0;
}


LRESULT CALLBACK WndProc(HWND window, UINT msg, WPARAM wparam, LPARAM lparam)
{
	switch(msg)
	{
		case WM_DESTROY:
			PostQuitMessage(0);
			break;

		case WM_INPUT:
			return HandleRawInput(window, msg, wparam, lparam);
			break;

		default:
			return DefWindowProc(window, msg, wparam, lparam);
	}

	return 0;
}
Any ideas how to actually get readable data back from the HID controller?

Share this post


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

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!