<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="500" height="500" style="border:1px solid #d3d3d3;" >
</canvas>
<script>
let canvas= document.getElementById("myCanvas");
let ctx = canvas.getContext("2d");
let x = 0;
let y = 50;
let text = "";
let arrtext = Array("");
let counter = 0;
document.onkeypress = function(e){
text += e.key;
if (e.key == 'Enter'){
counter = counter + 1;
text = "";
}
arrtext[counter] = text;
if (e.key === ' ' ) {
e.preventDefault();
}
window.scrollTo(0, 0);
ctx.clearRect(0,0,500,500);
for (let i = 0;i < arrtext.length;i++)
ctx.fillText(i+ " " + arrtext[i], x, y+i*25);
}
</script>
</body>
</html>
|