Hi,
I've been working on getting rid of DirectInput for handling keyboard and mouse input.
On the keyboard side I'm all good, but my current RAW mouse implementation (1st attempt) has two strange symptons:
1 - terrible 'lag' in movement, like it's 'dragging along' after the mouse physically stopped moving
2 - interference with keyboard input
Here's the code I use.
Any input is really appreciated.
// setting up the mouse
bool CInputHandler::SetupMouseRaw(const HWND pHwnd)
{
Rid[0].usUsagePage = HID_USAGE_PAGE_GENERIC;
Rid[0].usUsage = HID_USAGE_GENERIC_MOUSE;
Rid[0].dwFlags = RIDEV_CAPTUREMOUSE | RIDEV_INPUTSINK | RIDEV_NOLEGACY
Rid[0].hwndTarget = pHwnd;
RegisterRawInputDevices(Rid, 1, sizeof(Rid[0]));
mInitialized = true;
return true;
}
// updating the mouse
void CInputHandler::UpdateMouse(const int pPosX, const int pPosY)
{
mMousePosX = pPosX;
mMousePosY = pPosY;
mMouseMoved = true;
}
// windows messaging (WNDPROC)
// MOUSE INPUT: RAW
case WM_INPUT:
{
UINT dwSize = 40;
static BYTE lpb[40];
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER));
RAWINPUT* raw = (RAWINPUT*)lpb;
if(raw->header.dwType == RIM_TYPEMOUSE)
{
_input.UpdateMouse(raw->data.mouse.lLastX, raw->data.mouse.lLastY);
}
}
break;
// handling game input
if(_input.MouseMoved())
{
_d3dcam.FreeLook(_input.GetMousePosX(), _input.GetMousePosY(), _player.GetLookSpeed()); // * _timer.GetDelta());
_input.SetMouseMoved(false);
}