如何在Win32 API中生成击键组合?
-
24-10-2019 - |
题
我有此代码模拟窗口键的按压。但是,我将如何按下窗口+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);
}
解决方案
你必须打电话 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);
不隶属于 StackOverflow