持有CTRL时的后wm_keydown?

发布于 2025-02-08 02:28:35 字数 1336 浏览 1 评论 0原文

如果我在发送postmessage包含wm_keydown时将ctrl键向下键,则与消息“混乱”。

我不明白,如果它发送ctrl加上正在发送的消息,或者是什么?

如何复制:

启动记事本并按住ctrl键在代码运行时

#include <windows.h>
#include <iostream>

struct extraKeyInfo
{
    unsigned short repeatCount;
    unsigned char scanCode;
    bool extendedKey, prevKeyState, transitionState;

    operator unsigned int()
    {
        return repeatCount | (scanCode << 16) | (extendedKey << 24) |
            (prevKeyState << 30) | (transitionState << 31);
    }
};


int _tmain(int argc, _TCHAR* argv[])
{

    auto hwnd = FindWindow(0, L"Untitled - Notepad");
    HWND hEdit = FindWindowEx(hwnd, NULL, TEXT("Edit"), NULL);

    for (char ch = 'a'; ch <= 'z'; ch++) // Output a-z in Notepad
    {
        short vkCode = LOBYTE(VkKeyScan(ch));

        extraKeyInfo lParam = {};
        lParam.scanCode = MapVirtualKey(vkCode, MAPVK_VK_TO_VSC);

        PostMessage(hEdit, WM_KEYDOWN, vkCode, lParam);

        lParam.repeatCount = 1;
        lParam.prevKeyState = true;
        lParam.transitionState = true;

        PostMessage(hEdit, WM_KEYUP, vkCode, lParam);
        Sleep(200);
    }

}

可以以某种方式将所需的密钥仅发送到postmessage ippertion如果我有任何钥匙吗?

If i be holding the CTRL key down while sending a PostMessage containing WM_KEYDOWN it 'mess' with the message.

I couldn't understand what really happens, if it sends CTRL plus the message being sent or what?

How to reproduce:

Launch notepad and hold the CTRL key while the code is running

#include <windows.h>
#include <iostream>

struct extraKeyInfo
{
    unsigned short repeatCount;
    unsigned char scanCode;
    bool extendedKey, prevKeyState, transitionState;

    operator unsigned int()
    {
        return repeatCount | (scanCode << 16) | (extendedKey << 24) |
            (prevKeyState << 30) | (transitionState << 31);
    }
};


int _tmain(int argc, _TCHAR* argv[])
{

    auto hwnd = FindWindow(0, L"Untitled - Notepad");
    HWND hEdit = FindWindowEx(hwnd, NULL, TEXT("Edit"), NULL);

    for (char ch = 'a'; ch <= 'z'; ch++) // Output a-z in Notepad
    {
        short vkCode = LOBYTE(VkKeyScan(ch));

        extraKeyInfo lParam = {};
        lParam.scanCode = MapVirtualKey(vkCode, MAPVK_VK_TO_VSC);

        PostMessage(hEdit, WM_KEYDOWN, vkCode, lParam);

        lParam.repeatCount = 1;
        lParam.prevKeyState = true;
        lParam.transitionState = true;

        PostMessage(hEdit, WM_KEYUP, vkCode, lParam);
        Sleep(200);
    }

}

Is possible somehow to send just the desired key into the PostMessage independent if i have any keydown?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文