SendWait()
is slower because it expects the message to be processed by the target application. The Send()
function instead does not wait and returns as soon as possible. If the application is somehow busy, the difference may be even more obvious.
If you call Flush()
, you will stop your application to handle all events related to the keyboard queued in the message queue. This doesn't make much sense if you sent them using SendWait()
, and you slow down the application a lot because it is inside the loop (imagine Flush()
as selective DoEvents()
- with all its flaws - and it calls SendWait()
itself SendWait()
).
If you are interested in its performance (but they will always be limited by the speed with which your application can process messages), please read this on MSDN . In general, you can change the SendKeys
class to use the SendInput
function, rather than a log hook. As a quick link, just add this parameter to the app.config file:
<appSettings> <add key="SendKeys" value="SendInput"/> </appSettings>
In any case, the goal of the new implementation is not speed, but consistent behavior in different versions of Windows and options (increased performance is most likely a side effect).
source share