简体   繁体   English

使用SendInput API的最佳做法

[英]Best practices for using the SendInput API

I am working on an automated testing library, and want to simulate mouse and keyboard inputs using the SendInput Win32 API . 我正在使用自动化测试库,并且想使用SendInput Win32 API模拟鼠标和键盘输入。 This API allows one to push several input items in a single call to the API. 该API允许在一次调用中将多个输入项推送到该API。 There are a number of other examples and similar libraries throughout the web using SendInput. 使用SendInput在网络上还有许多其他示例和类似的库。 Many of them pass a single input operation for each call to the API. 对于每次对API的调用,它们中的许多传递一个输入操作。 Is there any advantage to batching inputs, or using a single input per call to SendInput? 批量输入或每次调用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. 在这两种情况下,SendInput通常可能出现的问题是,在您发送输入和目标应用程序接收输入之间,输入焦点可能会改变。 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. 在这种情况下,执行一系列连续的SendInputs与单个SendInput之间没有区别。

(I'm pretty sure that internally, SendInput is just looping over the inputs passed to it anyway...) (我很确定在内部,SendInput只是循环传递给它的输入...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM