Table of Contents
Customizing Hot Keys

Hot Keys for Built-in Commands

The WebView class allows you to define Shortcuts. The following code demonstrates how to define "Ctrl + B" for "Back" and "Ctrl + F" for "Forward":

WebView1.Shortcuts = new Shortcut[]
{
    //Ctrl + B triggers CommandIds.Back command
    new Shortcut(CommandIds.Back, KeyCodes.B, true, false, false),
    
    //Ctrl + F triggers CommandIds.Forward command
    new Shortcut(CommandIds.Forward, KeyCodes.F, true, false, false);
};

Once a shortcut is registered through the WebView's Shortcuts property, it works regardless where the keyboard focus is.

Hot Keys for Custom Commands

You can use CommandIds.RegisterUserCommand to register a user command. The following code demonstrates how to use this method:

//Register a user command
int nHomeCommand = CommandIds.RegisterUserCommand("Home");

Once the command is registered, you can associate it with a shortcut key:

WebView1.Shortcuts = new Shortcut[]
{
    //F10 triggers "Home" command
    new Shortcut(nHomeCommand, KeyCodes.F11, false, false, false),
    
    ....
};

When the command is invoked (for example, when the associated hot key is pressed, or when a menu item to which the command is associated with is selected), the WebView's Command event will be triggered. You can handle this event to carry out your custom action associated with the command.

//Attach the event handler
WebView1.Command += new CommandHandler(WebView_Command);

//Command event handler
void WebView_Command(object sender, CommandEventArgs e)
{
    WebView webView = (WebView)sender;
    if (e.CommandId == m_nHomeCommand)
        webView.Url = "http://www.essentialobjects.com";
}