如何在win32 api中生成击键组合?

发布于 2024-10-14 06:29:39 字数 416 浏览 4 评论 0原文


我有这段代码可以模拟按下窗口键。但是我如何才能按window+d键,基本上显示桌面。

void ShowDesktop(void)
{


  // Simulate a key press
     keybd_event( VK_LWIN,
                  0x5B,
                  KEYEVENTF_EXTENDEDKEY | 0,
                  0 );

  // Simulate a key release
     keybd_event( VK_LWIN,
                  0x5B,
                  KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
                  0);

}

i have this code that simulates the pressing of the window key. But how would i make it to press window+d key, essentially showing desktop.

void ShowDesktop(void)
{


  // Simulate a key press
     keybd_event( VK_LWIN,
                  0x5B,
                  KEYEVENTF_EXTENDEDKEY | 0,
                  0 );

  // Simulate a key release
     keybd_event( VK_LWIN,
                  0x5B,
                  KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
                  0);

}

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独难免 2024-10-21 06:29:39

您必须调用 keybd_event 函数与虚拟键值和 D 键的硬件扫描代码来获取该值,您可以使用 MapVirtualKey 函数。

尝试这个示例。

//simulate the Win key press
    keybd_event(VK_LWIN, 0x5B, 0, 0);
//simulate the 'D' key press,the 0x44 is the Virtual key value for the 'D' key, the 0x20 vaue is the hardware scan code for the 'D' key
    keybd_event(0x44, 0x20, 0, 0);
//simulate the 'D' key release
    keybd_event(0x44, 0x20, KEYEVENTF_KEYUP, 0);
//simulate the Win key release
    keybd_event(VK_LWIN, 0x5B, KEYEVENTF_KEYUP, 0);

you must call keybd_event function with the Virtual key value and the hardware scan code for the D key to get this value you can use the MapVirtualKey function.

try this sample.

//simulate the Win key press
    keybd_event(VK_LWIN, 0x5B, 0, 0);
//simulate the 'D' key press,the 0x44 is the Virtual key value for the 'D' key, the 0x20 vaue is the hardware scan code for the 'D' key
    keybd_event(0x44, 0x20, 0, 0);
//simulate the 'D' key release
    keybd_event(0x44, 0x20, KEYEVENTF_KEYUP, 0);
//simulate the Win key release
    keybd_event(VK_LWIN, 0x5B, KEYEVENTF_KEYUP, 0);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文