Search code examples
javascriptckeditorckeditor4.x

How to use combination of keys to call custom methods in CK Editor using 'key' event


I need to call one custom method with the combination of keys like "CTRL + P" in CK Editor. I tried for single key press event like an "Enter" and its working but my requirement is to be with combination of keys. Is there any way to achieve it?

                            ev.editor.on( 'key', function( e ) {
                                var evtobj = window.event ? event : e
                                if( evtobj.data.keyCode === 13 ) {
                                    ev.editor.execCommand( 'addCustomWidget' );
                                }
                            } );

Solution

  • Use setKeystroke()

    Assigns keystrokes associated with editor commands.

    Αssuming you have an CKEditor instance named editor1:

    CKEDITOR.instances.editor1.on('instanceReady', function(evt) {
        evt.editor.setKeystroke(CKEDITOR.CTRL + 80, 'addCustomWidget'); // CTRL + P
    });