.NET 中的 sendkeys 问题
我有一个 Windows 应用程序,我在其中使用发送键从一个窗口导航到另一个窗口。我的发送按键序列就像在我的应用程序中激活另一个窗口,然后将击键发送到该窗口。但是我发送的击键在我激活另一个窗口的同一窗口中得到更新。
但经过几次按键后,它就会转到另一个窗口。似乎是发送键的同步问题。有没有办法指定当前发送键的操作完成后,再发送下一个发送键。
I have a windows application, where I am using send keys to navigate from one window to another. My send key sequence is like activating another window with in my app, and sending key strokes to that window. But the key strokes I am sending is getting updated in the same window where I am activating the other window.
But after few key strokes it is going to the other window. Seems like synchonization issue with send keys. Is there a way to specify the operation of the current send key is finished, before sending the next sendkey.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现 sendkeys 根本不可靠。请尝试使用输入模拟器。
I have found sendkeys to be nothing but unreliable. Try the input simulator instead.
您是否尝试过使用 SendKeys.SendWait。这将等到密钥发送完毕并且操作处理完毕后再继续。
由于窗口位于您自己的应用程序中,为什么不提供一组函数来执行操作,而不是使用 SendKeys。一旦窗口创建并处于活动状态,函数就可以创建窗口,您可以通过处理 激活事件,然后您可以使用SendKeys将击键发送到新窗口,如果您确实需要的话,否则窗口类上再次有您可以调用的函数来携带列出击键将引发的操作。您可以定义一个通用的接口 Windows 实现来促进这种交互。
Have you tried using SendKeys.SendWait. This will wait until the key was sent and the action processed before carying on.
Since the windows are in your own application, why not provide set of functions to carry out the actions rather than using SendKeys. Functions can create the window once the windows in created and active which you can detect by handling the Activated event, you can then use SendKeys to send key strokes to the new window, if you really need to, otherwise again have functions on the window class that you can call to carry out the operations that the key strokes would induce. You could probably define a common interface that your windows implement to facilitate this interaction.