utils/keyboard
@ckeditor/ckeditor5-utils/src/keyboard
Set of utils related to keyboard support.
Filtering
Constants
-
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
-
Information about a keystroke.
Functions
-
getCode( Key ) → Number
Converts a key name or a keystroke info into a key code.
Note: Key names are matched with
keyCodes
in a case-insensitive way.Parameters
Key : String | KeystrokeInfo
name (see
keyCodes
) or a keystroke data object.
Returns
Number
Key or keystroke code.
-
getEnvKeystrokeText( keystroke ) → String
It translates any keystroke string text like
"CTRL+A"
to an environment–specific keystroke, i.e."⌘A"
on Mac OSX.Parameters
keystroke : String
Keystroke text.
Returns
String
Keystroke text specific for the environment.
-
getLocalizedArrowKeyCodeDirection( keyCode, contentLanguageDirection ) → 'left' | 'up' | 'right' | 'down'
Returns the direction in which the selection will move when a 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 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 : 'ltr' | 'rtl'
The content language direction, corresponding to
contentLanguageDirection
.
Returns
'left' | 'up' | 'right' | 'down'
Localized arrow direction.
-
isArrowKeyCode( keyCode ) → Boolean
Returns
true
if the provided key code represents one of the arrow keys. -
isForwardArrowKeyCode( keyCode, contentLanguageDirection ) → Boolean
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 : 'ltr' | 'rtl'
The content language direction, corresponding to
contentLanguageDirection
.
Returns
Boolean
-
parseKeystroke( keystroke ) → Number
Parses keystroke and returns a keystroke code that will match the code returned by link
getCode
for a 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).Parameters
keystroke : String | Array.<(Number | String)>
Keystroke definition.
Returns
Number
Keystroke code.
- as a single string – e.g.