When I want Javascript make an action on a key press I use the number of the key (e.g. for enter key it is 13) Does anyone know how to make shift+enter key? (for <br> in word or frontpage)
I want to set a textarea to catch shift + enter to run some code on the text instead of adding a new line:
[CODE]addEvent(txtArea_1,'keypress',con_keys);[/CODE] Here is the key catcher- it could be a switch with multiple cases,
but I just want the one: [CODE]function con_keys(e){ var E= allEve(e); var boo= E.shiftKey; var c= E.key; if(boo && c== 13){ if(E.preventDefault ) E.preventDefault(); else if (E.returnValue)E.returnValue= false; con_run(); } }[/CODE] the allEve function returns an event object with some key-event properties
for the Unknown browser: [CODE]function allEve(e){ var ev= (window.event)? window.event: e; if(!ev || !ev.type) return false; var ME= ev; ME.obj= Eve(e); if(ME.type.indexOf('key')!= -1){ if(iz('ie') || ME.type.indexOf('keypress')!= -1){ ME.key= (ev.keyCode)? ev.keyCode: ((ev.charCode)? ev.charCode: ev.which); } else ME.key= ev.charCode; if(ME.key) ME.letter= String.fromCharCode(ME.key); } return ME; }[/CODE] Here's a simple addEvent: [CODE] function addEvent(hoo,wot,fun){ if(hoo.addEventListener)hoo.addEventListener(wot,fun,null); else if(hoo.attachEvent)hoo.attachEvent('on'+wot,fun); else hoo['on'+wot]=fun; } [/CODE]
the iz('ie') is another story, you can leave it out for a keypress event, but you need it to catch keyup or keydown in IE
if i want the pointer in a text area to go to nextline (break one line down/ start a new text line) when the user press shift+enter....how should i modify ur code????