Please, dear Lord, no. No. Do not do this.
Use something with a sane key event handling system. List here: https://sw.kovidgoyal.net/kitty/keyboard-protocol/
(My particular use that drove me down this rabbit hole was using "Shift" for selection. You CANNOT DO THIS with "standard" terminals as you cannot detect when shift gets pressed or released without also pressing another key.)