# EditingKeystrokeHandler

class

A keystroke handler for editor editing. Its instance is available in [`keystrokes`](module_core_editor_editor-Editor.md#member-keystrokes) so plugins can register their keystrokes.

E.g. an undo plugin would do this:

```typescript
editor.keystrokes.set( 'Ctrl+Z', 'undo' );
editor.keystrokes.set( 'Ctrl+Shift+Z', 'redo' );
editor.keystrokes.set( 'Ctrl+Y', 'redo' );
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/editingkeystrokehandler.ts#L27)

<a id="properties">

## Properties

<a id="member-editor">

### `editor: Editor` _(readonly)_

The editor instance.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/editingkeystrokehandler.ts#L31)

<a id="methods">

## Methods

<a id="function-constructor">

### `constructor( editor )`

Creates an instance of the keystroke handler.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/editingkeystrokehandler.ts#L36)

#### Parameters

* `editor: Editor`

<a id="function-destroy">

### `destroy() → void` _(inherited)_

Destroys the keystroke handler.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/keystrokehandler.ts#L142)

#### Returns

* `void`

<a id="function-listenTo">

### `listenTo( emitter ) → void` _(inherited)_

Starts listening for `keydown` events from a given emitter.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/keystrokehandler.ts#L66)

#### Parameters

* `emitter: Window | Emitter | HTMLElement`

#### Returns

* `void`

<a id="function-press">

### `press( keyEvtData ) → boolean` _(inherited)_

Triggers a keystroke handler for a specified key combination, if such a keystroke was [defined](#function-set).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/keystrokehandler.ts#L128)

#### Parameters

* `keyEvtData: Readonly<KeystrokeInfo>`

  Key event data.

#### Returns

* `boolean`

  Whether the keystroke was handled.

<a id="function-set">

### `set( keystroke, callback, options = { options.priority? } ) → void`

Registers a handler for the specified keystroke.

The handler can be specified as a command name or a callback.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/editingkeystrokehandler.ts#L58)

#### Parameters

* `keystroke: string | Array<string | number>`

  Keystroke defined in a format accepted by the [`parseKeystroke`](module_utils_keyboard.md#function-parseKeystroke) function.

* `callback: EditingKeystrokeCallback`

  If a string is passed, then the keystroke will [execute a command](module_core_editor_editor-Editor.md#function-execute). If a function, then it will be called with the [key event data](module_engine_view_observer_keyobserver-ViewDocumentKeyEventData.md) object and a `cancel()` helper to both `preventDefault()` and `stopPropagation()` of the event.

* `options: object`

  Additional options.

  Properties

  * `options.priority?: PriorityString`

    The priority of the keystroke callback. The higher the priority value the sooner the callback will be executed. Keystrokes having the same priority are called in the order they were added.

  Defaults to `{}`

#### Returns

* `void`

<a id="function-stopListening">

### `stopListening( emitter? ) → void` _(inherited)_

Stops listening to `keydown` events from the given emitter.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/keystrokehandler.ts#L135)

#### Parameters

* `emitter?: Window | Emitter | HTMLElement`

#### Returns

* `void`

---

Full index of the CKEditor 5 API reference: [llms.txt](llms.txt)
