سؤال

I am working on an automated testing library, and want to simulate mouse and keyboard inputs using the SendInput Win32 API. This API allows one to push several input items in a single call to the API. There are a number of other examples and similar libraries throughout the web using SendInput. Many of them pass a single input operation for each call to the API. Is there any advantage to batching inputs, or using a single input per call to SendInput? The documentation doesn't seem to offer guidance, or perhaps I'm misreading it.

هل كانت مفيدة؟

المحلول

There's no real benefit to one technique vs the other that I know of. In either case, the usual potential problem with SendInput is that the input focus could change between when you send the input and when the input is received by the target application. The classic example is a modal dialog appearing asynchronously to alert the user of some problem, and ends up stealing focus, and soaking up the remaining input that was supposed to go elsewhere. There's no difference between doing a successive series of SendInputs vs a single SendInput in this scenario.

(I'm pretty sure that internally, SendInput is just looping over the inputs passed to it anyway...)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top