C++ Win32键转换代码输出不需要的按键

C++ Win32键转换代码输出不需要的按键,c++,winapi,keyboard,keyboard-hook,C++,Winapi,Keyboard,Keyboard Hook,我使用以下代码获取键盘状态的unicode字符串: std::wstring App::DecodeMessage(KBDLLHOOKSTRUCT* kbHook) { // Clean up the keyboard state for(int i=0; i<256; ++i) keyboardMap[i] = 0; // Get the state of all the virtual keys GetKeyboardState(keyboardMap

我使用以下代码获取键盘状态的unicode字符串:

std::wstring App::DecodeMessage(KBDLLHOOKSTRUCT* kbHook) {
    // Clean up the keyboard state
    for(int i=0; i<256; ++i) keyboardMap[i] = 0;

    // Get the state of all the virtual keys
    GetKeyboardState(keyboardMap);

    // Then we get the current layout setting
    HKL kbdLayout = GetKeyboardLayout(0);

    // We create the buffer to receive the unicode chars
    std::vector<wchar_t> buffer;
    buffer.resize(257);
    buffer.assign(257, L'\0');

    // And finally we translate all this to an unicode char
    int numberOfChars = ToUnicode(kbHook->vkCode, kbHook->scanCode, keyboardMap, &buffer[0], 256, 0);

    if(numberOfChars >= -1 && numberOfChars <= 0) return std::wstring(L"");

    return std::wstring(&buffer[0], numberOfChars);
}
std::wstring App::DecodeMessage(KBDLLHOOKSTRUCT*kbHook){
//清除键盘状态
用于(int i=0;ivkCode、kbHook->scanCode、键盘映射和缓冲区[0],256,0);

如果(numberOfChars>=-1&&numberOfChars所以我最终决定不使用ToUnicode。我最终使用了Marc AndréMoreau创建的解决方案,如果有人感兴趣,可以在找到该解决方案。

:提供给ToUnicode函数的参数可能不足以转换虚拟密钥代码,因为存储了以前的死密钥在键盘布局中。@IInspectable我认为这并不能解释当我在应用程序运行时按一个引号时,被关注的应用程序会得到另一个引号。如下所示:当应用程序运行时打开记事本键入“输出为”””,当应用程序不运行时则键入“输出为””。它解释了“似乎没有正确编码”迈克尔·卡普兰似乎得出了同样的结论:.
ToUnicode[Ex]
不能很好地处理死键。