I wanted to get the keyCode on keydown
event in ckeditor. My code looks somewhat like this:
editor.document.on( 'keydown', function(event) {
var keycode= event.data.keyCode & ~(CKEDITOR.SHIFT | CKEDITOR.CTRL |CKEDITOR.ALT);
alert('Key:'+keycode);
});
But it always alerts 0. Can't figure why is it so.?
Also I wanted to use event.preventDefault()
from jQuery, but I can't figure out how to include jQuery library in my plugin.js file. Any suggestions?
This is the correct code if you want to have fun:
CKEDITOR.instances.editor1.on( 'key', function (evt) {
var kc = evt.data.keyCode,
csa = ~(CKEDITOR.CTRL | CKEDITOR.SHIFT | CKEDITOR.ALT);
console.log(kc, kc & csa);
// kc & csa is what you need
});
Or this if you want to have shorter code:
CKEDITOR.instances.editor1.document.on( 'keydown', function (evt) {
console.log(evt.data.getKeystroke(), evt.data.getKey());
// getKey() is exactly what you want
});
Regarding preventing default - you don't need jQuery for this. CKEditor is so huge tool it has built-in DOM library. You can find preventDefault
method in the evt.data
from the second example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With