开发者

Is there any difference between keybd_event() and SendKeys.SendWait()?

Is SendKeys.SendWait() just a wrapper and these two code snippets are identical?

const int VK_ESCAPE = 0x1B;
keybd_event(VK_ESCAPE, 0, 0, 0);
keybd_event(VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0);

and

System.Windows.Forms.SendKeys.SendWait("{ESC}");

If n开发者_运维技巧ot, is there any reason to use one over the other?


keybd_event() is a legacy API, you're supposed to use SendInput() these days. SendKeys either uses a journaling hook or SendInput, depending on .config file setting. The journaling hook is legacy and still the default, SendInput works better on Vista and up, available since .NET 3. So, roughly, yes they are the same. The config setting is:

<appSettings> 
    <add key="SendKeys" value="SendInput"/> 
</appSettings> 


The most recent versions of System.Windows.Forms.SendKeys use SendInput, although you have to configure it to do so. Hans has explained about the alternative journaling hook method of SendKeys.

SendInput is the officially sanctioned API call for faking input. The documentation to keybd_event states:

Note This function has been superseded. Use SendInput instead.

You should probably use SendKeys because its lots easier.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜