Pre Process Message Event

SpiceLogic WinForms HTML Editor KeyBindings manager customizing keyboard shortcuts with EditorActionId and KeyBindingCombo at runtime

If you want to override editor keyboard shortcuts, use the KeyBindings property — that is the modern, supported way. The editor exposes a KeyBindingsManager instance on every control via editor.KeyBindings that lets you bind, rebind, override, disable, or re-enable any of the editor's built-in actions without writing low-level Win32 message handling.

The KeyBindingsManager API

KeyBindingsManager API surface for the SpiceLogic WinForms HTML Editor exposing Bind, Unbind, Override, Disable, and Enable methods for keyboard shortcuts

The manager exposes these public methods:

Bind(action, combo)Maps a KeyBindingCombo to an EditorActionId. Throws if the combo is already bound to a different action.
Unbind(action)Removes the current combo for an action (no-op if unbound).
GetBinding(action)Returns the currently bound combo, or null.
AllBindingsRead-only snapshot of every action → combo pair currently registered.
Override(action, handler)Replaces the editor's default behaviour for an action with your own Action delegate. Pass null to clear.
Disable(action)Suppresses both default routing and any override; the keystroke is consumed silently.
Enable(action)Reverses a previous Disable.
IsDisabled(action)Returns true if the action has been disabled.

A KeyBindingCombo is constructed from four arguments: ctrl, alt, shift (each a bool) and virtualKeyCode (an int Win32 VK code). WinForms callers can cast System.Windows.Forms.Keys directly to int.

Sample — rebind, disable, and add a combo

KeyBindingCombo constructor binding Ctrl+Shift+H to the EditorActionId.HyperLinkInsert action in the SpiceLogic WinForms HTML Editor
using SpiceLogic.HtmlEditor.Abstractions.KeyBindings;

using System.Windows.Forms;



// 1) Rebind Ctrl+B from Bold to "Save". First detach the action that

//    currently owns Ctrl+B (if any), then bind Save to the freed combo.

editor.KeyBindings.Unbind(EditorActionId.Bold);

editor.KeyBindings.Bind(

    EditorActionId.Save,

    new KeyBindingCombo(ctrl: true, alt: false, shift: false, virtualKeyCode: (int)Keys.B));



// 2) Disable Ctrl+O (Open). The keystroke will be swallowed silently

//    instead of opening the default Open File dialog.

editor.KeyBindings.Bind(

    EditorActionId.Open,

    new KeyBindingCombo(ctrl: true, alt: false, shift: false, virtualKeyCode: (int)Keys.O));

editor.KeyBindings.Disable(EditorActionId.Open);



// 3) Add a brand-new combo: Ctrl+Shift+H -> insert a hyperlink, but

//    route through your own handler instead of the default dialog.

editor.KeyBindings.Bind(

    EditorActionId.HyperLinkInsert,

    new KeyBindingCombo(ctrl: true, alt: false, shift: true, virtualKeyCode: (int)Keys.H));

editor.KeyBindings.Override(EditorActionId.HyperLinkInsert, () =>

{

    MessageBox.Show("Custom hyperlink workflow goes here.");

});

EditorActionId values

EditorActionId enum IntelliSense list of bindable actions for keyboard shortcuts in the SpiceLogic WinForms HTML Editor KeyBindings manager

Every action you can bind. Names mirror the toolbar items they correspond to.

New, Open, SaveDocument lifecycle.
Cut, Copy, Paste, PasteFromMsWord, PrintClipboard and printing.
Undo, RedoUndo stack.
Bold, Italic, Underline, Subscript, Superscript, StrikeThroughInline character formatting.
Search, SpellCheck, FormatReset, BodyStyleFind/replace, spell-check, clear-formatting, body style dialog.
HorizontalRule, OrderedList, UnOrderedListBlock-level inserts and lists.
AlignLeft, AlignCenter, AlignRightParagraph alignment.
Outdent, IndentParagraph indent.
TableInsert, ImageInsert, HyperLinkInsert, SymbolInsert, YouTubeVideoInsertElement insert dialogs.
TextHighlightColor, FontForeColorColour pickers.

Two combos are pre-bound on construction: Search → Ctrl+F (replaces IE's built-in Find dialog) and Paste → Ctrl+V (replaces IE's paste, which doubles style spans). Everything else is bind-able but unbound by default — browser/MSHTML shortcuts like Ctrl+B/I/U/Z/Y/A/C/X/P execute natively for performance.

Legacy — the PreProcessMessageEvent escape hatch

Legacy PreProcessMessageEvent handler in the SpiceLogic WinForms HTML Editor intercepting WM_KEYDOWN for advanced keyboard shortcut scenarios beyond KeyBindings

For low-level Win32 WM_KEYDOWN interception that KeyBindings does not cover (for example, intercepting non-character keys or peeking at raw message lParam bits), the editor still raises the PreProcessMessageEvent. This is an advanced hook — prefer KeyBindings whenever it suffices.

private const int WM_KEYDOWN = 0x100;

private const int VK_F1     = 0x70;



private void Editor_PreProcessMessageEvent(object sender, PreProcessMessageEventArg e)

{

    // Intercept F1 inside the editor surface and show custom help.

    if (e.Message.Msg == WM_KEYDOWN && e.Message.WParam.ToInt32() == VK_F1)

    {

        ShowMyHelpDialog();

        e.Handled = true; // swallow the keystroke

    }

}

Wire it up the usual way (editor.PreProcessMessageEvent += Editor_PreProcessMessageEvent;). Set e.Handled = true to suppress the default routing; leave it false to let the editor — and then KeyBindings — continue handling the message.

Last updated on May 14, 2026