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

inf*_*oop 1 keyboard winapi keycode keyboard-events keystrokes


我有这个代码模拟按下窗口键.但是如何按下窗口+ 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);

}
Run Code Online (Sandbox Code Playgroud)

RRU*_*RUZ 7

你必须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);
Run Code Online (Sandbox Code Playgroud)