I have recently started reading Beginning DirectX 11 Programming(Allen Sherrod, Wendy Jones) and have stumbled upon a problem concerning input. The book only teaches me how to use Win32, DirectInput and XInput for input-handling. After a bit of research, however, I have realized that I should be using RawInput for input handling. This is where the problem arises.

I have managed to enable my application to receive raw mouse input. My question to you guys is: how do I interpret the raw mouse data and use it in my game, similar to how you use WM_MOUSEMOVE?

Edit: Sorry for formulating myself badly. I want to know where the mouse pointer is located within the screen of my application but don't understand the values of the mouse's raw input. (mX, mY)

case WM_INPUT:

{

UINT bufferSize;

GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &bufferSize, sizeof(RAWINPUTHEADER));

BYTE *buffer = new BYTE[bufferSize];

GetRawInputData((HRAWINPUT)lParam, RID_INPUT, (LPVOID)buffer, &bufferSize, sizeof(RAWINPUTHEADER));

RAWINPUT *raw = (RAWINPUT*) buffer;

if ( raw->header.dwType == RIM_TYPEMOUSE)

{

long mX = raw->data.mouse.lLastX;

long mY = raw->data.mouse.lLastY;

}

}

解决方案

You could achieve this by doing it like this:

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)

{

int xPosRelative = raw->data.mouse.lLastX;

int yPosRelative = raw->data.mouse.lLastY;

}

break;

}

As mentioned in Mouse movement with WM_INPUT(Article applies to non-high definition aswell). The article contains an example of WM_MOUSEMOVE aswell.

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐