这段代码会报错 说没有成员 SetDeviceState 也没有SetDeviceData#include pchh#define DIRECTINPUT_VERSION 0x0800#include dinputh#pragma commentlib dinput8lib#pragma commentlib dxguidlibLPDIRECTINPUT8 g_pDI = NULL;LPDIRE
这段代码可能会报错,因为DirectInput中没有成员函数SetDeviceState和SetDeviceData。在函数MoveMouse中,应该使用SetDeviceState来设置鼠标状态,而不是SetDeviceData。正确的代码应该是:
// 模拟鼠标移动 void MoveMouse(int deltaX, int deltaY) { DIMOUSESTATE2 dims; memset(&dims, 0, sizeof(dims));
// 先 Acquire 鼠标设备
g_pMouse->Acquire();
// 获取设备状态
if (SUCCEEDED(g_pMouse->GetDeviceState(sizeof(DIMOUSESTATE2), &dims)))
{
// 修改鼠标状态
dims.lX += deltaX;
dims.lY += deltaY;
// 设置鼠标状态
g_pMouse->SetDeviceState(sizeof(DIMOUSESTATE2), &dims);
}
// 释放鼠标设备
g_pMouse->Unacquire();
}
原文地址: https://www.cveoy.top/t/topic/bG7H 著作权归作者所有。请勿转载和采集!