有没有办法劫持 System.Windows.Forms.WebBrowser 控件处理的键盘快捷键?
我有一个 WebBrowser 控件,用于在我们的应用程序中生成格式化的 HTML 代码。但是,当 WebBrowserShortcutsEnabled 设置为 true 时,控件会处理复制/剪切/粘贴/全选等键盘快捷键。这些操作可以由控件本身处理,但是,有一些操作(例如在父控件中使用的 Ctrl+S 应该用于保存/全部保存等)。当 WebBrowser 控件具有焦点时,这些操作其他键盘快捷键不会传递到父控件。有没有办法以编程方式劫持这些键盘事件?
我尝试使用 PreviewKeyPress 事件将单个击键传递给父控件,但在传递多个击键时遇到困难。有什么想法吗?
I have a WebBrowser control that is used to generate formatted HTML code in our application. However, keyboard shortcuts like Copy/Cut/Paste/SelectAll are handed by the control when WebBrowserShortcutsEnabled is set to true. These operations are fine to be handled by the control itself, however, there are certain operations such as Ctrl+S that are used in the parent control that should be used to Save/Save All, etc. When the WebBrowser control has focus, these other keyboard shortcuts are not passed to the parent control. Is there a way I can hijack these keyboard events programattically?
I have tried using the PreviewKeyPress event to pass single keystrokes to the parent control but I am having a difficult time passing multiple keystrokes. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试覆盖 WndProc
否则,此 答案 显示如何使用 SetWindowsHookEx 应该得到如果一切都失败了,你就在那里。
You can try override WndProc
Otherwise, this answer shows how to capture keystrokes using SetWindowsHookEx which should get you there if all else fails.