当前位置:   article > 正文

getrawinputdata鼠标,原始鼠标输入的解释

getrawlnputdata参数解析

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.

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号