简体   繁体   中英

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. 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?

You can try override 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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