我的应用程序无法识别从 SendKeys 或 SendInput 发送的击键,但可以识别从键盘发送的击键
我有一个自制的应用程序(Master),它定义了一堆热键。我需要使用另一个外部应用程序(控制)来自动化该应用程序。我无法重建主应用程序,它可以运行,已经安装并且不能被弄乱。
如果我使用键盘,在 Master 上使用热键就像一个魅力。
所以,我想我可以使用 SendKeys.SendWait 或 SendKeys.Send 发送命令。虽然我的代码可以与其他应用程序(例如记事本)配合使用,但它无法与我的自定义应用程序 Master 配合使用。这可能有多种原因 - Master 比较老,混合了 .NET、C++...一些低级视频控件...谁知道幕后是什么。
我需要获得更高水平的东西。我需要能够发送击键,就像它们来自键盘本身一样。我不希望计算机能够区分发送按键的物理键盘和发送按键的应用程序。
我可以使用什么以及它会有什么不同?
I've got a homegrown app (Master) that has a bunch of hotkeys defined. I need to automate the app with another external app (Control). I cannot rebuild the Master app, it runs, is already installed and can't be messed with.
Using hotkeys on Master works like a charm if I use a keyboard.
So, I figure I an use SendKeys.SendWait or SendKeys.Send to send the commands. While my code works fine with other apps (such as Notepad) it is not working with my custom app, Master. This could be for a number of reasons - Master is older, has .NET, C++ mixed... some low level video controls... who knows what's under the covers.
I need to get something higher level. I need to be able to send the keystrokes as if they are coming from the keyboard itself. I don't want the computer to be able to differentiate between the physical keyboard sending the keys and my app sending the keys.
What can I use and how will it be different?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题不在于 SendKeys。
我尝试了 SendKeys.Send、SendKeys.SendWait、SendInput 和 keybd_event。
后来我意识到激活应用程序和发送击键之间的时间太短了。我等待了 200 毫秒,但只需将其增加到 500 毫秒,我就解决了我的问题。
由于嵌入了视频播放器,该应用程序花费了很长时间来绘制。再给它 300 毫秒,让它准备好接受我发送给它的击键。
The problem was not SendKeys.
I tried SendKeys.Send, SendKeys.SendWait, SendInput and keybd_event.
I later realized that the time between activating the application and the time sending the keystrokes was too short. I was waiting 200ms but simply by increasing this to 500ms I solved my problem.
The application took a long time to draw because of the embedded video players. Giving it another 300ms allowed it to be ready for the keystrokes I was sending it.