tags:

views:

409

answers:

1

Hi all:

Seems like this should be obvious, but how do I send arrow key presses to a process using Expect.pm? Does it depend on the terminal type I am using (vt100) or do I send keyboard scancodes?

TIA.

+2  A: 

It does indeed depend on your current TERM environment variable. Once that's set correctly (say VT220 or linux), then arrow keys are

up:    "\c[[A"
down:  "\c[[B"
left:  "\c[[D"
right: "\c[[C"
Jonathan Feinberg
This seems like the right approach, but something isn't quite working - when I transmit the codes, the application gives an unrecognised input error. I am SSHing to the remote server, setting TERM in bash, then running the command-line app (which wont start unless TERM is set to a recognised value: "VT100" and "VT220" are okay, "linux" is not). Do I also need to set the TERM in some way for my Perl script or for my local machine's shell? Any idea where I'd get information on this topic? The Expect.pm docs suggest this is something of a black art, which is discouraging.
Anon Guy
You've marked the answer "accepted". Does that mean you've figured out what wasn't working?
Jonathan Feinberg
I haven't figured out what isn't working, but I suspect the current problem is not sending arrow keys, it is something slightly else to do with sending data and how the VT100 receives data in fields on the screen. I think the next step is the VT100 documentation, but if you have any tips on where to set the Expect.pm-side TERM or what to set it to that woudl be great too.
Anon Guy
To clarify, I have just confirmed I can send the right arrow command, but vt100 is not responding to it as I expect it to: I send "\c[[C" and then "\r\n", and the application is responding with "Continue <C> or Abort <A>:" -- an apparent error message I am unable to replicate using the keyboard.
Anon Guy
And when I write it down I realise how stupid I have been. Sending "\r" instead of "\r\n" did the trick. (Previous parts of the program must have been ignoring the "\n" but this part doesn't seem to like it.) Sorted - thanks again.
Anon Guy
Being away from my computer while yo ufigured it all out was the best thing I could have done. :)
Jonathan Feinberg