1/* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17(function() { 18// keyCode 229 means composing text, so get the last character in 19// e.target.value. 20// keycode 64(@)-95(_) is mapped to a ctrl code 21// keycode 97(A)-122(Z) is converted to a small letter, and mapped to ctrl code 22window.term.attachCustomKeyEventHandler((e) => { 23 if (window.ctrl) { 24 keyCode = e.keyCode; 25 if (keyCode === 229) { 26 keyCode = e.target.value.charAt(e.target.selectionStart - 1).charCodeAt(); 27 } 28 if (64 <= keyCode && keyCode <= 95) { 29 input = String.fromCharCode(keyCode - 64); 30 } else if (97 <= keyCode && keyCode <= 122) { 31 input = String.fromCharCode(keyCode - 96); 32 } else { 33 return true; 34 } 35 if (e.type === 'keyup') { 36 window.term.input(input); 37 e.target.value = e.target.value.slice(0, -1); 38 window.ctrl = false; 39 } 40 return false; 41 } else { 42 return true; 43 } 44}); 45})();