简体   繁体   English

有没有办法劫持System.Windows.Forms.WebBrowser控件处理的键盘快捷键?

[英]Is there a way to hijack the keyboard shortcuts that are handled by the System.Windows.Forms.WebBrowser control?

I have a WebBrowser control that is used to generate formatted HTML code in our application. 我有一个WebBrowser控件,该控件用于在我们的应用程序中生成格式化的HTML代码。 However, keyboard shortcuts like Copy/Cut/Paste/SelectAll are handed by the control when WebBrowserShortcutsEnabled is set to true. 但是,当WebBrowserShortcutsEnabled设置为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. 这些操作可以很好地由控件本身处理,但是,某些控件(例如Ctrl + S)在父控件中使用,应用于“保存/保存所有”等。当WebBrowser控件具有焦点时,这些其他键盘快捷键不会传递给父控件。 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. 我尝试使用PreviewKeyPress事件将单个击键传递给父控件,但是传递多个击键很困难。 Any ideas? 有任何想法吗?

You can try override WndProc 您可以尝试覆盖WndProc

protected override void WndProc(ref Message m)
{
    //Check Msg and WParam for your combination...

    base.WndProc(ref m);
}

Otherwise, this answer shows how to capture keystrokes using SetWindowsHookEx which should get you there if all else fails. 否则,此答案说明如何使用SetWindowsHookEx捕获击键,如果其他所有操作均失败,则应该可以将您带到那里。

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

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