KeyboardHandler (interface)

January 12, 2020 ยท View on GitHub

API categories | API index

KeyboardHandler (interface)

This handler allows you to handle events related to keyboard input and is called only for the main frame. For an example of how to implement handler see cefpython.CreateBrowser().

Table of contents:

Callbacks

OnPreKeyEvent

ParameterType
browserBrowser
eventKeyEvent
event_handleMSG* / GdkEvent* / NSEvent*`
is_keyboard_shortcut_outlist
Returnbool

Called before a keyboard event is sent to the renderer. |event| contains information about the keyboard event. |event_handle| is the operating system event message, if any. Return true if the event was handled or false otherwise. If the event will be handled in OnKeyEvent() as a keyboard shortcut, set |is_keyboard_shortcut_out[0]| to True and return False.

KeyEvent is a dictionary with the following keys:

KeyTypeDescription
typeKeyEventTypeThe type of keyboard event
modifiersKeyEventFlagsBit flags describing any pressed modifier keys
windows_key_codeintThe 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 "chromium/KeyboardCodes.h" for a list of values.
native_key_codeintThe actual key code generated by the platform
is_system_keyboolIndicates whether the event is considered a "system key" event. For Windows see WM_SYSKEYDOWN. This value will always be false on non-Windows platforms.
characterwchar_t or unsigned shortThe character generated by the keystroke
unmodified_characterwchar_t or unsigned shortSame as 'character' but unmodified by any concurrently-held modifiers (except shift). This is useful for working out shortcut keys.
focus_on_editable_fieldboolTrue if the focus is currently on an editable field on the page. This is useful for determining if standard key events should be intercepted.

KeyEventType constants defined in the cefpython module:

  • KEYEVENT_RAWKEYDOWN - Notification that a key transitioned from "up" to "down".
  • KEYEVENT_KEYDOWN - Notification that a key was pressed. This does not necessarily correspond to a character depending on the key and language. Use KEYEVENT_CHAR for character input.
  • KEYEVENT_KEYUP - Notification that a key was released.
  • KEYEVENT_CHAR - Notification that a character was typed. Use this for text input. Key down events may generate 0, 1, or more than one character event depending on the key, locale, and operating system.

KeyEventFlags constants defined in the cefpython module:

  • EVENTFLAG_NONE
  • EVENTFLAG_CAPS_LOCK_ON
  • EVENTFLAG_SHIFT_DOWN
  • EVENTFLAG_CONTROL_DOWN
  • EVENTFLAG_ALT_DOWN
  • EVENTFLAG_LEFT_MOUSE_BUTTON
  • EVENTFLAG_MIDDLE_MOUSE_BUTTON
  • EVENTFLAG_RIGHT_MOUSE_BUTTON
  • EVENTFLAG_COMMAND_DOWN (Mac)
  • EVENTFLAG_NUM_LOCK_ON (Mac)
  • EVENTFLAG_IS_KEY_PAD (Mac)
  • EVENTFLAG_IS_LEFT (Mac)
  • EVENTFLAG_IS_RIGHT (Mac)

OnKeyEvent

ParameterType
browserBrowser
eventKeyEvent
event_handleMSG* / GdkEvent* / NSEvent*
Returnbool

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 if the keyboard event was handled or false otherwise. Description of the KeyEvent type is in the OnPreKeyEvent() callback.