utils/keyboard
@ckeditor/ckeditor5-utils/src/keyboard
Filtering
Constants
-
keyCodes : object
module:utils/keyboard#keyCodes
An object with
keyName => keyCode
pairs for a set of known keys.Contains:
a-z
,0-9
,f1-f12
,`
,-
,=
,[
,]
,;
,'
,,
,.
,/
,\
,arrow(left|up|right|bottom)
,backspace
,delete
,enter
,esc
,tab
,ctrl
,cmd
,shift
,alt
.
Interfaces
-
KeystrokeInfo
module:utils/keyboard~KeystrokeInfo
Type Definitions
-
ArrowKeyCodeDirection
module:utils/keyboard~ArrowKeyCodeDirection
Functions
-
getCode( key ) → number
module:utils/keyboard~getCode
Converts a key name or keystroke info into a key code.
Note: Key names are matched with
keyCodes
in a case-insensitive way.Parameters
key : string | Readonly<KeystrokeInfo>
A key name (see
keyCodes
) or a keystroke data object.
Returns
number
Key or keystroke code.
-
getEnvKeystrokeText( keystroke ) → string
module:utils/keyboard~getEnvKeystrokeText
Translates any keystroke string text like
"Ctrl+A"
to an environment–specific keystroke, i.e."⌘A"
on macOS.Parameters
keystroke : string
The keystroke text.
Returns
string
The keystroke text specific for the environment.
-
getLocalizedArrowKeyCodeDirection( keyCode, contentLanguageDirection ) → ArrowKeyCodeDirection | undefined
module:utils/keyboard~getLocalizedArrowKeyCodeDirection
Returns the direction in which the selection will move when the provided arrow key code is pressed considering the language direction of the editor content.
For instance, in right–to–left (RTL) content languages, pressing the left arrow means moving the selection right (forward) in the model structure. Similarly, pressing the right arrow moves the selection left (backward).
Parameters
keyCode : number
A key code as in
keyCode
.contentLanguageDirection : LanguageDirection
The content language direction, corresponding to
contentLanguageDirection
.
Returns
ArrowKeyCodeDirection | undefined
Localized arrow direction or
undefined
for non-arrow key codes.
-
isArrowKeyCode( keyCode ) → boolean
module:utils/keyboard~isArrowKeyCode
Returns
true
if the provided key code represents one of the arrow keys.Parameters
keyCode : number
A key code as in
keyCode
.
Returns
boolean
-
isForwardArrowKeyCode( keyCode, contentLanguageDirection ) → boolean
module:utils/keyboard~isForwardArrowKeyCode
Determines if the provided key code moves the selection forward or backward considering the language direction of the editor content.
For instance, in right–to–left (RTL) languages, pressing the left arrow means moving forward in the model structure. Similarly, pressing the right arrow moves the selection backward.
Parameters
keyCode : number
A key code as in
keyCode
.contentLanguageDirection : LanguageDirection
The content language direction, corresponding to
contentLanguageDirection
.
Returns
boolean
-
parseKeystroke( keystroke ) → number
module:utils/keyboard~parseKeystroke
Parses the keystroke and returns a keystroke code that will match the code returned by
getCode
for the corresponding keystroke info.The keystroke can be passed in two formats:
- as a single string – e.g.
ctrl + A
, - as an array of known key names and key codes – e.g.:
[ 'ctrl', 32 ]
(ctrl + space),[ 'ctrl', 'a' ]
(ctrl + A).
Note: Key names are matched with
keyCodes
in a case-insensitive way.Note: Only keystrokes with a single non-modifier key are supported (e.g.
ctrl+A
is OK, butctrl+A+B
is not).Note: On macOS, keystroke handling is translating the
Ctrl
key to theCmd
key and handling only that keystroke. For example, a registered keystrokeCtrl+A
will be translated toCmd+A
on macOS. To disable the translation of some keystroke, use the forced modifier:Ctrl!+A
(note the exclamation mark).Parameters
keystroke : string | readonly Array<string | number>
The keystroke definition.
Returns
number
Keystroke code.
- as a single string – e.g.
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing? Please report it via our issue tracker.
With the release of version 42.0.0, we have rewritten much of our documentation to reflect the new import paths and features. We appreciate your feedback to help us ensure its accuracy and completeness.