首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >管理输入带有DirectX DirectInput的鼠标

管理输入带有DirectX DirectInput的鼠标
EN

Stack Overflow用户
提问于 2013-09-16 14:06:21
回答 1查看 2.7K关注 0票数 1

我尝试使用DirectX输入来管理输入鼠标。但是当我试图获取鼠标的X和Y坐标时,值是不正确的(负值或似乎是随机的)。

我向你们展示了我使用的代码:

代码语言:javascript
复制
bool    System::frame()
{
    bool result;
    if (input->isButtonDown(BUTTON_L)) //if left button is down
    {
        result = ReadMouse();
        if(!result)
            return false;
        ProcessInput();
    }
}

bool System::ReadMouse()
{
    HRESULT result;

    //this->mouseState is a DIMOUSESTATE ; this->mouse is a LDIRECTINPUTDEVICE8
    result = this->mouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&this->mouseState);
    if(FAILED(result))
    {
        if((result == DIERR_INPUTLOST) || (result == DIERR_NOTACQUIRED))
            this->mouse->Acquire();
        else
            return false;
    }
    return true;
}

void System::ProcessInput()
{
    this->mouseX = this->mouseState.lX;
    this->mouseY = this->mouseState.lY;

    if(this->mouseX < 0)
        this->mouseX = 0;
    if(this->mouseY < 0)
        this->mouseY = 0;

    if(this->mouseX > this->ScreenWidth)
        this->mouseX = this->ScreenWidth;
    if(this->mouseY > this->ScreenHeight)
        this->mouseY = this->ScreenHeight;
    return;
}

我的最后一个测试给了this->mouseX = -657this->mouseY = -36,而不是200200 (大约)。当我初始化鼠标时,我会检查这个函数,它们看起来很有效(我遵循了一个教程)。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-16 14:15:44

我认为原因是DirectInput给出了鼠标位置的相关数据。有关如何从鼠标解释数据以及如何切换到绝对模式的说明,请参见:http://msdn.microsoft.com/en-us/library/windows/desktop/ee418272(v=vs.85).aspx

建议使用原始输入API而不是DirectInput。(http://msdn.microsoft.com/en-us/library/windows/desktop/ms645536(v=vs.85).aspx

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18830051

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档