原始鼠标输入的解释 [英] Interpretation of raw mouse input
问题描述
我最近开始阅读开始DirectX 11编程(Allen Sherrod,Wendy Jones),并且偶然发现了一个关于输入的问题。本书只教我如何使用Win32,DirectInput和XInput进行输入处理。然而,经过一番研究,我意识到我应该使用RawInput进行输入处理。这是出现问题的地方。
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.
我已经设法使我的应用程序接收原始鼠标输入。我对你的问题是:如何解释原始鼠标数据并在我的游戏中使用它,类似于你如何使用WM_MOUSEMOVE?
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?
编辑:对不起,制定我自己严重。我想知道鼠标指针位于我的应用程序的屏幕中,但不明白鼠标的原始输入的值。 (mX,mY)
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;
}
}
推荐答案
可以这样做:
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;
}
如鼠标移动与WM_INPUT (文章适用于非高清aswell)。本文包含一个WM_MOUSEMOVE aswell的示例。
As mentioned in Mouse movement with WM_INPUT(Article applies to non-high definition aswell). The article contains an example of WM_MOUSEMOVE aswell.
这篇关于原始鼠标输入的解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!