[5160] | 1 | var EA_keys = {8:"Retour arriere",9:"Tabulation",12:"Milieu (pave numerique)",13:"Entrer",16:"Shift",17:"Ctrl",18:"Alt",19:"Pause",20:"Verr Maj",27:"Esc",32:"Space",33:"Page up",34:"Page down",35:"End",36:"Begin",37:"Left",38:"Up",39:"Right",40:"Down",44:"Impr ecran",45:"Inser",46:"Suppr",91:"Menu Demarrer Windows / touche pomme Mac",92:"Menu Demarrer Windows",93:"Menu contextuel Windows",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"Verr Num",145:"Arret defil"}; |
---|
| 2 | |
---|
| 3 | |
---|
| 4 | |
---|
| 5 | function keyDown(e){ |
---|
| 6 | if(!e){ // if IE |
---|
| 7 | e=event; |
---|
| 8 | } |
---|
| 9 | |
---|
| 10 | // send the event to the plugins |
---|
| 11 | for(var i in editArea.plugins){ |
---|
| 12 | if(typeof(editArea.plugins[i].onkeydown)=="function"){ |
---|
| 13 | if(editArea.plugins[i].onkeydown(e)===false){ // stop propaging |
---|
| 14 | if(editArea.isIE) |
---|
| 15 | e.keyCode=0; |
---|
| 16 | return false; |
---|
| 17 | } |
---|
| 18 | } |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | var target_id=(e.target || e.srcElement).id; |
---|
| 22 | var use=false; |
---|
| 23 | if (EA_keys[e.keyCode]) |
---|
| 24 | letter=EA_keys[e.keyCode]; |
---|
| 25 | else |
---|
| 26 | letter=String.fromCharCode(e.keyCode); |
---|
| 27 | |
---|
| 28 | var low_letter= letter.toLowerCase(); |
---|
| 29 | |
---|
| 30 | if(letter=="Page up" && !AltPressed(e) && !editArea.isOpera){ |
---|
| 31 | editArea.execCommand("scroll_page", {"dir": "up", "shift": ShiftPressed(e)}); |
---|
| 32 | use=true; |
---|
| 33 | }else if(letter=="Page down" && !AltPressed(e) && !editArea.isOpera){ |
---|
| 34 | editArea.execCommand("scroll_page", {"dir": "down", "shift": ShiftPressed(e)}); |
---|
| 35 | use=true; |
---|
| 36 | }else if(editArea.is_editable==false){ |
---|
| 37 | // do nothing but also do nothing else (allow to navigate with page up and page down) |
---|
| 38 | return true; |
---|
| 39 | }else if(letter=="Tabulation" && target_id=="textarea" && !CtrlPressed(e) && !AltPressed(e)){ |
---|
| 40 | if(ShiftPressed(e)) |
---|
| 41 | editArea.execCommand("invert_tab_selection"); |
---|
| 42 | else |
---|
| 43 | editArea.execCommand("tab_selection"); |
---|
| 44 | |
---|
| 45 | use=true; |
---|
| 46 | if(editArea.isOpera || (editArea.isFirefox && editArea.isMac) ) // opera && firefox mac can't cancel tabulation events... |
---|
| 47 | setTimeout("editArea.execCommand('focus');", 1); |
---|
| 48 | }else if(letter=="Entrer" && target_id=="textarea"){ |
---|
| 49 | if(editArea.press_enter()) |
---|
| 50 | use=true; |
---|
| 51 | }else if(letter=="Entrer" && target_id=="area_search"){ |
---|
| 52 | editArea.execCommand("area_search"); |
---|
| 53 | use=true; |
---|
| 54 | }else if(letter=="Esc"){ |
---|
| 55 | editArea.execCommand("close_all_inline_popup", e); |
---|
| 56 | use=true; |
---|
| 57 | }else if(CtrlPressed(e) && !AltPressed(e) && !ShiftPressed(e)){ |
---|
| 58 | switch(low_letter){ |
---|
| 59 | case "f": |
---|
| 60 | editArea.execCommand("area_search"); |
---|
| 61 | use=true; |
---|
| 62 | break; |
---|
| 63 | case "r": |
---|
| 64 | editArea.execCommand("area_replace"); |
---|
| 65 | use=true; |
---|
| 66 | break; |
---|
| 67 | case "q": |
---|
| 68 | editArea.execCommand("close_all_inline_popup", e); |
---|
| 69 | use=true; |
---|
| 70 | break; |
---|
| 71 | case "h": |
---|
| 72 | editArea.execCommand("change_highlight"); |
---|
| 73 | use=true; |
---|
| 74 | break; |
---|
| 75 | case "g": |
---|
| 76 | setTimeout("editArea.execCommand('go_to_line');", 5); // the prompt stop the return false otherwise |
---|
| 77 | use=true; |
---|
| 78 | break; |
---|
| 79 | case "e": |
---|
| 80 | editArea.execCommand("show_help"); |
---|
| 81 | use=true; |
---|
| 82 | break; |
---|
| 83 | case "z": |
---|
| 84 | use=true; |
---|
| 85 | editArea.execCommand("undo"); |
---|
| 86 | break; |
---|
| 87 | case "y": |
---|
| 88 | use=true; |
---|
| 89 | editArea.execCommand("redo"); |
---|
| 90 | break; |
---|
| 91 | default: |
---|
| 92 | break; |
---|
| 93 | } |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | // check to disable the redo possibility if the textarea content change |
---|
| 97 | if(editArea.next.length > 0){ |
---|
| 98 | setTimeout("editArea.check_redo();", 10); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | setTimeout("editArea.check_file_changes();", 10); |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | if(use){ |
---|
| 105 | // in case of a control that sould'nt be used by IE but that is used => THROW a javascript error that will stop key action |
---|
| 106 | if(editArea.isIE) |
---|
| 107 | e.keyCode=0; |
---|
| 108 | return false; |
---|
| 109 | } |
---|
| 110 | //alert("Test: "+ letter + " ("+e.keyCode+") ALT: "+ AltPressed(e) + " CTRL "+ CtrlPressed(e) + " SHIFT "+ ShiftPressed(e)); |
---|
| 111 | |
---|
| 112 | return true; |
---|
| 113 | |
---|
| 114 | }; |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | // return true if Alt key is pressed |
---|
| 118 | function AltPressed(e) { |
---|
| 119 | if (window.event) { |
---|
| 120 | return (window.event.altKey); |
---|
| 121 | } else { |
---|
| 122 | if(e.modifiers) |
---|
| 123 | return (e.altKey || (e.modifiers % 2)); |
---|
| 124 | else |
---|
| 125 | return e.altKey; |
---|
| 126 | } |
---|
| 127 | }; |
---|
| 128 | |
---|
| 129 | // return true if Ctrl key is pressed |
---|
| 130 | function CtrlPressed(e) { |
---|
| 131 | if (window.event) { |
---|
| 132 | return (window.event.ctrlKey); |
---|
| 133 | } else { |
---|
| 134 | return (e.ctrlKey || (e.modifiers==2) || (e.modifiers==3) || (e.modifiers>5)); |
---|
| 135 | } |
---|
| 136 | }; |
---|
| 137 | |
---|
| 138 | // return true if Shift key is pressed |
---|
| 139 | function ShiftPressed(e) { |
---|
| 140 | if (window.event) { |
---|
| 141 | return (window.event.shiftKey); |
---|
| 142 | } else { |
---|
| 143 | return (e.shiftKey || (e.modifiers>3)); |
---|
| 144 | } |
---|
| 145 | }; |
---|