c# SendKey到隐藏窗口
我有一个隐藏的窗口,我想向它发送一个按键。我想要实现的一个示例是一个应用程序,它将按 F5 键发送到不是活动窗口的网络浏览器。当收到 F5 按键时,Web 浏览器会知道刷新当前页面。
我还想向应用程序发送组合键,例如 Ctrl+S。这种用法的一个示例是定时自动保存功能,用于不具有自动保存功能的应用程序。这将使我不必记住每 5 分钟保存一次。
C# 是我的技术,这听起来现实吗?
I have a window which is hidden and I would like to send a keypress to it. An example of what I'm trying to achieve is an app that will send the key F5 to a web browser which wasn't the active window. The web browser would know to refresh the current page when the F5 keystroke is received.
I would also like to send a combination of keys to an application, e.g. Ctrl+S. One example of this usage could be a timed auto-save feature to use with applications which don't have autosave. This would spare me having to remember to save every 5 mins.
C# is my technology, does this sound realistic?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这篇 CodeProject 文章展示了如何将击键发送到外部应用程序(使用 C# 源代码)代码)。
This CodeProject article shows how to send keystrokes to an external application (with C# source code).
您可以使用 WinApi 来实现此目的。
SendMessage
或PostMessage
方法将所需的消息发送到您的应用程序。以下是 SendMessage 的 C# 定义
,并定义要发送的消息,如下所示:
检查 PInvoke - 包含 .NET WinApi 方法定义的优秀资源
You can use WinApi for this purpose.
SendMessage
orPostMessage
method to send desired message to your application.Here's C# definition of SendMessage
and define the message that you want to send like:
Check PInvoke - great resource containing WinApi method definitions for .NET
这应该是可能的,查看 www.pinvoke.net 并搜索 sendinput,该页面应该告诉您需要知道的一切,以及如何找到窗口(查找 findwindow)
This should be possible, look at www.pinvoke.net and search for sendinput, that page should tell you everything you need to know, also how to find the window (look for findwindow)