0

Is it possible to automatically detect the escape sequence for a key combination?

, i.e., instead of running cat followed by pressing ctrl+right or ctrl+left manually to detect the escape sequence as ^[[5C or ^[[5D respectively, can it be automated? In that case, we may be able to send fn(ctrl+left) or fn(ctrl+right) as input to cat via pipe and get the output(for the first time, when ^[[5C or ^[[5D are unknown) directly.

fn(char a[]='ctrl+right') {..outputs the actual keypress signal for the input string a.. ;} | cat; fn=?

This question is the exact reverse of my other question https://stackoverflow.com/questions/34547008/reverse-map-the-keys-binding-value-to-the-key-combination.

I am asking this to automate the process of setting up key-bindings in the terminals, for devs, so that they need not run manually for all possible combinations, as we had to do now (as seen here)

Community
  • 1
  • 1
  • I don't understand the question. `cat` is how you find out the escape sequence for a keypress. Are you asking how to turn the *words* `ctrl+right` into the appropriate key sequence? – Etan Reisner Dec 31 '15 at 14:24
  • Yup. Instead of manually pressing ctrl+left into the keyboard, is there any way that i can send it programmatically. if possible, is it also possible for all combinations of the keys – Thirukka Karnan Dec 31 '15 at 14:46
  • What's the point here? And isn't that exactly what the terminfo option in the documentation does? – Etan Reisner Jan 01 '16 at 19:47

1 Answers1

0

Is it possible to automatically detect the escape sequence for a key combination?

Since the shell (as any user program) has no insight into the terminal driver, it cannot predict what the driver will do with a key combination. Consider also that with certain terminals we can change the keyboard's behavior (e. g. cf. xmodmap). Automatic detection is not universally possible.

Armali
  • 18,255
  • 14
  • 57
  • 171