Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Years ago on AIX I used to create a file of key strokes, including function keys (mainly F3 and F12) into a file, and used that file as input to an INFORMIX program, to automated tasks, something like this:
fglgo myprogram.fgo <keystrokefile.txt
Now, I'm using Aubit language on GNU/Linux, and I'd like to do the same kind of thing, but I can't recall how I worked out the chars for the function keys, I'm using a different emulation (xterm), and I can't work out what characters to put in the key stroke file.
My $TERM variable contains "xterm".
If I type "infocmp", I get this:
I can see the "\E" chars above, and I understand that I can do Ctrl-V followed by the next char to get them into a file. Having tried several things, I can't get it to work, and I'm not even sure which are the F3 and F12 chars. (I recall there's some offset by 1?).
Questions:
1. Is the above infocmp output the place I should get the information I need?
2. What chars do I need to put into my file to simulate me pressing F3 and F12?
3. Is there a way for me to put such chars in a file by just pressing those function keys (I tried a here document, but that doesn't work (it's as if the function keys are not even pressed)).
Thanks heaps!
Tel7
Click here to see the post LQ members have rated as the most helpful post in this thread.
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541
Rep:
The "\E" is escape (the Esc key) that you can get (in vi, say) by typing Ctrl-M then Ctrl-[.
For example, the F1 key (kf1=\EOP) produces escape-upper case letter O-upper case letter P.
Now, to get those into a file you can start with the output of infocmp (which is showing you the definitions of all the functions that xterm "knows" about); if you use
Code:
infocmp -1 > filename
you'll get each capability on an individual line (which you can then edit, replacing the "\E" with the value of the escape key:
That "-1" switch of infocmp makes it more readable, thanks.
Ctrl-M doesn't work for me - it just creates a newline (as expected). As mentioned in my last post, I've been using Ctrl-V (it works).
I was doing:
Code:
Ctrl-V <Esc>
for the \E, but I think I was just looking at the wrong code from infocmp. I now see that I can also do:
Code:
Ctrl-V <F3>
which means I don't even need infocmp anymore. And I now notice that Ctrl-V also works outside of vi, so I can use the above when creating a here document, too!
Hi catkin,
Good suggestion about the "script" command. I forgot about it - haven't used it in years. I'm not sure if it's working from the application, because there's so much application stuff that I can't see the wood for the trees. It seems to work from the command line, when I preceed the function keys with Ctrl-V, but it's still messy. The here document seems to give me what I need, except for one thing... It would be easier if I can create the keystroke file while running the application. How can I tell Linux to take my keystrokes, and feed them to the application and to a file (e.g. presumably somehow using the "tee" command)?
So, thanks, both of you, for your help so far.
Despite the good progress, my automated sessions are not working as cleanly as I had hoped. I'm getting errors output from my sessions including things like this:
Code:
tcgetattr():: Inappropriate ioctl for device
tcsetattr():: Inappropriate ioctl for device
Any ideas why?
Also, I'd like to slow down the sessions, so I can see what's happening if things go wrong. I tried writing this Perl script (called "slow.pl") which takes the keystroke file as input, and outputs it, one byte per second:
Code:
#!/usr/bin/perl
$|=1;
while ($line = <>)
{
for ($i=0; $i<length($line); $i++)
{
print substr($line,$i,1);
sleep 1;
}
}
and running it like this:
slow.pl <keys.in | mypgm.4ae
and it works until it hits a function key, and then it just displays the chars that make up that function key, one at a time, in the field I'm in a the time, instead of just actioning that function key. Is this some multi-byte char issue, or what? Any ideas how I can resolve it, or do I need to go to a Perl forum?
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541
Rep:
Yer welcome.
Bear in mind that, if you've got codes in a file, the line terminator is a line feed (ASCII NL, Ctrl-J), not a carriage return (ASCII CR, Ctrl-M); see the chart below for top of a cross-reference (for whatever it may be worth).
Also, unless you display the codes as in the chart; i.e., as decimal, hex or octal, you won't be able to see them -- they'll just do what the function key (or control key) does. And, yeah, the only way you can isolate the shell or enter codes into a file with an editor is to use Ctrl-V followed by the non-printing code you want (pain in the hiney, eh?). I'm not a Perl type, so I dunno how you'd do that with it but it's dirt simple with C -- just do a raw write to send the function key string (or use the printf formatting codes to be able to see the values).
What the function keys do is "print" a series of values, starting with escape, character by character, stopping at a terminator (the terminator is not "printed").
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.