Jump to content

I've been working on a text editor for canvas that works via javascript. Does anyone know how to translate the mouse cursor to the next line with the enter key?

Also is it possible to have it place images in it as well and display a text cursor?

 

This my function for the keys so far:

	        function addletter(letter) { // Gets letter input and adds it to the position of the cursor	            keyHistory += letter;	            ctx.clearRect(0, 0, 300, 300);	            ctx.fillText(keyHistory, 20, 20);	        }	        function keyUpHandler(event) { // Gets the user input and adds it as the parameter for the addletter function	            var letters = "abcdefghijklmnopqrstuvwxyz";	            var key = event.keyCode;	            if (key > 64 && key < 91) {	                var letter = letters.substring(key - 64, key - 65);	                addletter(letter);	            }	            if (key == 13){ // keycode for enter	            }	        }

My canvas is 800 wide by 1200 in height.

"Instinct or Rationality; Which will you choose? Enchanted by a superiority complex"

"what you do in spite of internet speed is inspiring. :3" From Cae - 2015

Link to comment
https://linustechtips.com/topic/246731-javascript-canvas-mouse-cursor/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×