<KeyCode>-<TerminalCode>-<CharCode>

A story which begins on the keyboard, goes through a pseudo-terminal, and ends up on the screen.

Now that you love ptypipe (see previous post), we are ready to pipe everything and finally control gdb:

$ makefifo input.cli
$ python ptypipe.py "" "gdb -q" < input.cli | myGreatControlProgram > input.cli

Step 1: get the keystrokes from a HTML text input

<input id="readline"></input>
document.getElementById("readline").addEventListener("keypress", function(e) {
    var c = e.which;
    console.log(String.fromCharCode(c));
});
document.getElementById("readline").addEventListener("keydown", function(e) {
    var c = e.which;
    console.log(c);
}, false);

Step 2: loop-up the corresponding terminal code

$ showkey -a

Press any keys - Ctrl-D will terminate this program

^[[A         27 0033 0x1b
             91 0133 0x5b
             65 0101 0x41

I typed arrow-up on the keyboard.

Step 3: send the ASCII character

String.fromCharCode(27,91,65)