【问题标题】:how to generate keystroke combination in win32 api?如何在win32 api中生成击键组合?
【发布时间】:2011-06-14 23:39:35
【问题描述】:


我有这段代码可以模拟按下窗口键。但是我如何让它按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);

}

【问题讨论】:

    标签: winapi keyboard keyboard-events keycode keystrokes


    【解决方案1】:

    您必须使用虚拟键值和 D 键的硬件扫描码调用 keybd_event 函数来获取此值,您可以使用 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);
    

    【讨论】:

      猜你喜欢
      • 2017-09-08
      • 2012-03-01
      • 2013-03-17
      • 2018-03-19
      • 2021-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多