HID Data From Raw Input

Started by
-1 comments, last by NickGravelyn 17 years, 9 months ago
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?

This topic is closed to new replies.

Advertisement