I am following the below js fiddle. https://jsfiddle.net/Jonah/sbtoukan/1/
The code I am following is as below:
var canvas = new fabric.Canvas('container');
var oText = new fabric.IText('Tap and Type', {
left: 0,
top: 0,
fontFamily: 'Bree Serif',
fontSize: 22,
cache: false
});
canvas.on("mouse:over", clearText);
function clearText(e) {
if (e.target.type === "i-text") {
if (e.target.text === "Tap and Type") {
e.target.text = "";
canvas.renderAll();
};
}
}
canvas.add(oText);
In the above code I am implementing mouse related event such as I am implementing mouse:over
. When I hover the mouse on text then I am successfully implementing the cleartext function.
But I want that when I press some key then it should clear the text.
I reviewed this link:- https://github.com/fabricjs/fabric.js/wiki/Working-with-events to add mouse:over
functionality, but I did not get that how to add keydown event in my fabric canvas. Please help.