From 4bc9ea4573e47e22460f301d29e0e47cabc3a2e3 Mon Sep 17 00:00:00 2001 From: Mohit Bansal Date: Thu, 9 Feb 2023 12:55:44 +0530 Subject: [PATCH] add keypress handler's event --- src/viewer.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/viewer.js b/src/viewer.js index 1b2d4834..faa3dd80 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -295,6 +295,7 @@ $.Viewer = function( options ) { dblClickDistThreshold: this.dblClickDistThreshold, contextMenuHandler: $.delegate( this, onCanvasContextMenu ), keyDownHandler: $.delegate( this, onCanvasKeyDown ), + keyHandler: $.delegate( this, onCanvasKeyPress ), clickHandler: $.delegate( this, onCanvasClick ), dblClickHandler: $.delegate( this, onCanvasDblClick ), dragHandler: $.delegate( this, onCanvasDrag ), @@ -2884,6 +2885,29 @@ function onCanvasKeyDown( event ) { } } +function onCanvasKeyPress( event ) { + var canvasKeyPressEventArgs = { + originalEvent: event.originalEvent, + preventDefaultAction: false, + preventVerticalPan: event.preventVerticalPan || !this.panVertical, + preventHorizontalPan: event.preventHorizontalPan || !this.panHorizontal + }; + + /** + * Raised when a keyboard key is pressed and the focus is on the {@link OpenSeadragon.Viewer#canvas} element. + * + * @event canvas-key-press + * @memberof OpenSeadragon.Viewer + * @type {object} + * @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event. + * @property {Object} originalEvent - The original DOM event. + * @property {Boolean} preventDefaultAction - Set to true to prevent default keyboard behaviour. Default: false. + * @property {Boolean} preventVerticalPan - Set to true to prevent keyboard vertical panning. Default: false. + * @property {Boolean} preventHorizontalPan - Set to true to prevent keyboard horizontal panning. Default: false. + * @property {?Object} userData - Arbitrary subscriber-defined object. + */ + this.raiseEvent('canvas-key-press', canvasKeyPressEventArgs); +} function onCanvasClick( event ) { var gestureSettings;