开发者

how to generate keystroke combination in win32 api?

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,
                  KEYEVENT开发者_开发百科F_EXTENDEDKEY | 0,
                  0 );

  // Simulate a key release
     keybd_event( VK_LWIN,
                  0x5B,
                  KEYEVENTF_EXTENDEDKEY | 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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜