1

Can you simulate the keystroke shift+ enter in javascript? Basically when a user presses enter on the keyboard while in a div where contenteditable=true I want it to be as if they held down shift and enter at the same time. something like the following:

if(e.which == 13) 
    simulate shift and enter key being pressed simultaneously 

I'm doing this because I want the curser to go to a new line as soon as you press enter and I read this can be achieved by pressing shift+enter. I have the following code now:

        $('element[contenteditable="true"]').keypress(function(event) {

        if (event.which == 13){
            document.execCommand('innerHTML', false, 'p');
            $('element').append('<br>');

            return false;               
        }
    });

This code replaces auto generated p tags in IE with br tags but does not go to a new line when the enter key is pressed. the cursor only moves to a new line when I press another key after the enter key has been pressed. Any thoughts?

Cœur
  • 37,241
  • 25
  • 195
  • 267
webDev
  • 109
  • 9
  • Nothing special happens in a contenteditable when pressing `shift + enter`, unless you create something that listens to that key combination ? – adeneo Feb 10 '16 at 15:01
  • This question has been answer here: http://stackoverflow.com/questions/5203407/javascript-multiple-keys-pressed-at-once – Rumoch Feb 10 '16 at 15:30

0 Answers0