The CEF code comments for those events are these :
TChromium.OnPreKeyEvent
Code: Select all
///
// Called before a keyboard event is sent to the renderer. |event| contains
// information about the keyboard event. |os_event| is the operating system
// event message, if any. Return true (1) if the event was handled or false
// (0) otherwise. If the event will be handled in on_key_event() as a keyboard
// shortcut set |is_keyboard_shortcut| to true (1) and return false (0).
///
TChromium.OnKeyEvent
Code: Select all
///
// Called after the renderer and JavaScript in the page has had a chance to
// handle the event. |event| contains information about the keyboard event.
// |os_event| is the operating system event message, if any. Return true (1)
// if the keyboard event was handled or false (0) otherwise.
///
The
event parameter is a pointer to this Delphi record :
Code: Select all
TCefKeyEvent = record
kind : TCefKeyEventType; // called 'type' in the original CEF3 source code
modifiers : TCefEventFlags;
windows_key_code : Integer;
native_key_code : Integer;
is_system_key : Integer;
character : WideChar;
unmodified_character : WideChar;
focus_on_editable_field : Integer;
end;
...which has these CEF code comments :
Code: Select all
typedef struct _cef_key_event_t {
///
// The type of keyboard event.
///
cef_key_event_type_t type;
///
// Bit flags describing any pressed modifier keys. See
// cef_event_flags_t for values.
///
uint32 modifiers;
///
// The Windows key code for the key event. This value is used by the DOM
// specification. Sometimes it comes directly from the event (i.e. on
// Windows) and sometimes it's determined using a mapping function. See
// WebCore/platform/chromium/KeyboardCodes.h for the list of values.
///
int windows_key_code;
///
// The actual key code genenerated by the platform.
///
int native_key_code;
///
// Indicates whether the event is considered a "system key" event (see
// http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx for details).
// This value will always be false on non-Windows platforms.
///
int is_system_key;
///
// The character generated by the keystroke.
///
char16 character;
///
// Same as |character| but unmodified by any concurrently-held modifiers
// (except shift). This is useful for working out shortcut keys.
///
char16 unmodified_character;
///
// True if the focus is currently on an editable field on the page. This is
// useful for determining if standard key events should be intercepted.
///
int focus_on_editable_field;
} cef_key_event_t;
The "event.modifiers" can have these bit flags :
Code: Select all
EVENTFLAG_NONE = 0;
EVENTFLAG_CAPS_LOCK_ON = 1 shl 0;
EVENTFLAG_SHIFT_DOWN = 1 shl 1;
EVENTFLAG_CONTROL_DOWN = 1 shl 2;
EVENTFLAG_ALT_DOWN = 1 shl 3;
EVENTFLAG_LEFT_MOUSE_BUTTON = 1 shl 4;
EVENTFLAG_MIDDLE_MOUSE_BUTTON = 1 shl 5;
EVENTFLAG_RIGHT_MOUSE_BUTTON = 1 shl 6;
EVENTFLAG_COMMAND_DOWN = 1 shl 7;
EVENTFLAG_NUM_LOCK_ON = 1 shl 8;
EVENTFLAG_IS_KEY_PAD = 1 shl 9;
EVENTFLAG_IS_LEFT = 1 shl 10;
EVENTFLAG_IS_RIGHT = 1 shl 11;
If you just need to send a message to the form with all pressed key information then you only need to use TChromium.OnPreKeyEvent and set "
Result" and "
isKeyboardShortcut" to false. The "
event" record has all the information you need.
However, if you need to intercept and block some key before it reaches the browser then you need to use TChromium.OnPreKeyEvent and TChromium.OnKeyEvent.
There are some rare cases where some keys or mouse buttons don't trigger those events. For example, some buttons in multimedia mice and keyboards.
In those cases you will need to use TChromium.RenderHandle with SetWindowLongPtr to intercept raw windows messages.