处理原始输入 - 未定义的虚拟键打印输出

时间:2017-09-21 18:10:48

标签: c++ winapi input

我正在制作基于Raw Input API的输入系统。但是,我无法区分左/右移位。此外,还有一些我无法理解的打印输出,并希望得到一些澄清!

我使用以下代码段打印输入键码

case WM_INPUT:
{
    // Forward declaration
    RAWINPUT     input;
    HRAWINPUT    handle = reinterpret_cast<HRAWINPUT>(lParam);
    UINT         szData = sizeof(RAWINPUT);

    // Fetch the current input
    GetRawInputData(handle, RID_INPUT, &input, &szData, sizeof(RAWINPUTHEADER));

    // Determine input type and update accordingly
    switch (input.header.dwType)
    {
        case RIM_TYPEMOUSE:     Input::UpdateMouse(input.data.mouse, WindowSystem::WindowHandler);      break;
        case RIM_TYPEKEYBOARD:  Input::UpdateKeyboard(input.data.keyboard);                             break;

        default:                                                                                        break;
    }

    break;
}

void Input::UpdateKeyboard(const RAWKEYBOARD & data)
{
    // Fetch the current key code
    const auto & keyCode = data.VKey;

    std::cout << "Getting key: " << std::hex << (unsigned short)keyCode << std::endl;
// Ensure the virtual key is within the range of 
// virtual keys that we are dealing with
if (keyCode < (numKeys) )
{
    const auto  & Flag = data.Flags;                                        // Reference to input map key state

    // Update the input map according to the raw input key state
    // 1. Key pressed
    if      (Flag == (RI_KEY_MAKE  | RI_KEY_E0) || (Flag == (RI_KEY_MAKE)))
    { 
        SetKeystateDown(keyCode); 
    }

    // 2. Key not pressed
    else if ( (Flag == (RI_KEY_BREAK | RI_KEY_E0)) || (Flag == (RI_KEY_BREAK)) )
    { 
        SetKeystateUp(keyCode); 
    }
}

当键盘字母等其他键给出正确的键码打印输出时,键盘右侧的键给我一些奇怪的打印输出。

即。键盘Q输出0x51,而右键控制输出0xff和0x11

非常感谢有关此主题的任何帮助!谢谢!

0 个答案:

没有答案