in FF, i\'ve used this code:
if (keyCount == lineLimit) {
// method in FF, no Chrome
var mock = document.createEvent(\"KeyboardEvent\"); // or KeysEvent
This works, but it's not generating a keypress-event, rather a text-insert event.
var te = document.createEvent('TextEvent');
te.initTextEvent('textInput', true, true, window, 'test');
<element>.dispatchEvent(te);
That inserts the word 'test' at the end of the input (in your case you'd probably replace that by \n.