I use this code http://www.openjs.com/scripts/events/keyboard_shortcuts/index.php for handling keyboard shortcuts.
shortcut.add("Ctrl+Z",function() {
setTimeout(function() {
var val= $("textarea").val();
var length = val.split("\n").length;
alert(length);
}, 100);
},{
'type':'keydown',
'propagate':true,
'target':document.getElementById("textarea")
});
I have problem when ctrl+z is pressed and there is nothing to undo - the alerts 2 ,not 1.