getrawinputdata(getrawinputdata鼠标,RAWINPUT-如何获取鼠标滚轮数据[亲测有效])

发布时间:2025-12-10 19:16:18 浏览次数:11

getrawinputdata鼠标,RAWINPUT-如何获取鼠标滚轮数据[亲测有效]-

getrawinputdata鼠标,RAWINPUT-如何获取鼠标滚轮数据[亲测有效]I’musingrawinputwithdirectx…i’mtryingtozoomwiththecamerawhenmousewheelisused…whenIruntheprogramwiththefollowingcode,thedataIgetfromrawinputfortheusbuttondatagoest…

I’m using rawinput with directx…i’m trying to zoom with the camera when mouse wheel is used…when I run the program with the following code, the data I get from rawinput for the usbuttondata goes to 120 when I push mouse wheel forward…then it goes out of control…up to 65000…I thought the data was supposed to be 1 or -1 or 0…what does rawinput send as the mouse wheel data?

code:

LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg,

WPARAM wParam, LPARAM lParam)

{

switch(Msg)

{

case WM_CREATE:

{

RAWINPUTDEVICE Rid[2];

// Keyboard

Rid[0].usUsagePage = 1;

Rid[0].usUsage = 6;

Rid[0].dwFlags = 0;

Rid[0].hwndTarget=Inst.Wnd.hWnd;

// Mouse

Rid[1].usUsagePage = 1;

Rid[1].usUsage = 2;

Rid[1].dwFlags = 0;

Rid[1].hwndTarget=Inst.Wnd.hWnd;

if (!RegisterRawInputDevices(Rid,2,sizeof(RAWINPUTDEVICE)))

{

MessageBox(NULL, L”Failed to Register Input Devices!”, L”ALERT”, MB_OK);

exit(1);

}

return 0;

}

case WM_INPUT:

{

// Determine how big the buffer should be

UINT iBuffer;

GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &iBuffer,

sizeof(RAWINPUTHEADER));

LPBYTE lpb = new BYTE[iBuffer];

if (lpb == NULL)

{

return 0;

}

UINT readSize = GetRawInputData( (HRAWINPUT)lParam, RID_INPUT, lpb, &iBuffer, sizeof(RAWINPUTHEADER) ) ;

if( readSize != iBuffer )

puts( “ERROR: GetRawInputData didn’t return correct size!” ) ;

RAWINPUT *raw = (RAWINPUT*) lpb;

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

{

riProcessMouseMessage(&raw->data.mouse);

}

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

{

//riProcessKeyboardMessage(&raw->data.keyboard);

}

}

return 0;

case WM_COMMAND:

switch(LOWORD(wParam))

{

case IDM_FILE_NEW:

{

// Create the game object

pGame = new CGame(dxMgr.getD3DDevice());

// Initialize the game object

if (!pGame->init(Inst.Wnd.hWnd))

return 0;

break;

}

case IDM_FILE_OPEN:

pGame->m_animCollection->LoadXFile(“oxana.x”, 0);

//objects.CreateNewObject(1, L”oxana.x”, NULL);

break;

case IDM_FILE_SAVE:

break;

case IDM_FILE_SAVEAS:

break;

case IDM_FILE_EXIT:

PostQuitMessage(WM_QUIT);

break;

}

return 0;

case WM_DESTROY:

PostQuitMessage(WM_QUIT);

return 0;

default:

return DefWindowProc(hWnd, Msg, wParam, lParam);

}

return TRUE;

}

void riProcessMouseMessage( const RAWMOUSE* rmouse )

{

if(pGame != NULL)

{

//MessageBox(NULL, L”Game Found”, L”SUCCESS”, MB_OK);

if ( MOUSE_MOVE_RELATIVE == rmouse->usFlags )

{

riMgr.mxr = &rmouse->lLastX;

riMgr.myr = &rmouse->lLastY;

}

riMgr.mzr = (RI_MOUSE_WHEEL & rmouse->usButtonFlags) ? &rmouse->usButtonData : 0;

}

}

解决方案

I suspect it is the same as WM_MOUSEWHEEL:

The high-order word indicates the distance the wheel is rotated, expressed in multiples or pisions of WHEEL_DELTA, which is 120. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user.

The low-order word indicates whether various virtual keys are down.

Therefore you need to extract the high order word. You need to take care to handle negative values correctly. You probably don’t as you get large values instead.

If you want you can use the following macro for this: GET_WHEEL_DELTA_WPARAM(wParam)

需要做网站?需要网络推广?欢迎咨询客户经理 13272073477