LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Programming function keys (http://www.linuxquestions.org/questions/linux-software-2/programming-function-keys-110304/)

dazdaz 10-30-2003 05:23 AM

Programming function keys
 
I am using putty and logging in with a bash shell. No X.

I would like to figure out how to program the function keys, so I press say F1 and it outputs a command.

So far, I can't figure out how to do this.

Any help appreciated, thanks

dazdaz 10-30-2003 08:07 AM

I found an article here, although it did'nt work and required root!

http://groups.google.com/groups?q=li...ell.edu&rnum=2


I want to do this as any, i.e. non-root!

dazdaz 10-30-2003 09:25 AM

ok it's something like this : although i hav;nt figured out the
exact bash syntax.

bind -x "\x59" "echo hello"

guygriffiths 10-30-2003 10:36 AM

Sounds like you're 99% of the way there. Put the commands in ~/.bash_profile if you want them all of the time.

dazdaz 10-31-2003 05:45 AM

Nope I still can't figure this out. Can anybody help? Thanks

guygriffiths 10-31-2003 07:34 AM

What's the problem? What does bind do? Try looking for help about "alias", that should also do the trick

musrum 10-31-2003 08:15 AM

AFAIK alias won't do the trick. Bind is the correct approach. I think you just have a syntax problem. For your example:

bind -x '"\x59": "echo hello"'

Note the single quotes around everything after the -x. Also note the : after the key specification

dazdaz 10-31-2003 10:36 AM

Appreciate everyone's post. Thanks.

Unfortunately the last example does'nt work.

> echo $TERM
linux

I thought 3b in hex or 59 in decimal was the F1 key.

$ bind -x '"\x3b": "echo hello"'

Any idea why it won't work?

Also which settings should I use under Terminal/Keyboard in PuTTY for ' the function keys and keypad'.

The options are :

* Esc[n~
* Linux
* Xterm R6
* VT400
* VT100+
* SCO

Regards

musrum 10-31-2003 11:50 AM

I've never used PuTTY. But in bash, the syntax I gave you is correct. I don't know what key has the code \x59. Incidentally, \x59 specifies 59 hex, not 59 decimal.

To test your setup, try:

bind -x '"H": "echo hello"'

After than, capital H should result in hello being echoed to the console. If it doesn't, then we have a problem. BTW, when trying the syntax I gave you, did the shell complain? If the syntax is correct, you should see no response to the bind command. Also, if immediately after issuing the bind command you execute

echo $?

It should echo '0' if the bind command succeeded. If it doesn't, then the command failed.

Y0jiMb0 10-31-2003 02:59 PM

Two questions about this?
1) How do you 'unbind'? for instance if you do
Code:

bind -x '"H": "echo hello"'
and later you want to use the 'H', how do you recover it? I tryed several things but it doesn't works, in fact all becomes worst :mad:
2) Where can I find the code of every key?
Regards

musrum 10-31-2003 03:04 PM

To unbind H you would have to bind using the form

bind '"\nnn": self-insert'

Where nnn is replaced by the octal for the H key keycode, which I don't know.

But, theres an easy way: exit the shell. Bindings are not persistent nor global, they are local to the instance of bash in which you excecuted the bind command.

Y0jiMb0 10-31-2003 03:46 PM

Thank you for your very quick answer!
Code:

To unbind H you would have to bind using the form

bind '"\nnn": self-insert'

Where nnn is replaced by the octal for the H key keycode, which I don't know.

I found the codes; for instance they are in the book of Paul Sheer ("LINUX: Rute user's...") page 38. (They are the ascii codes, of course... or this is what I think) :D
But I cannot unbind. I did what you said: first
Code:

bind '"\110":"echo hello"'
('\110' is the code for 'H')
second
Code:

bind '"\110":echo hello'
and now when I press 'H' I get nothing (well, I get 'beep')
I tryed many combinations... and it doesn't work (the same happens if I type 'H' instead of the code) It always gets worst and worst :cry:
Code:

But, theres an easy way: exit the shell. Bindings are not persistent nor global, they are local to the instance of bash in which you excecuted the bind command.
Well, I know, but it is not very elegant, is it? :tisk:
Any idea?
Regards

musrum 11-01-2003 09:42 AM

Yep, what I said should work, thats bind 'self-insert' to the H key. The bindings take emacs and vi functions. The 'self-insert' function means insert the value of the key, i.e., in your case 'H'. So:

bind ':\110": self-insert'

Y0jiMb0 11-02-2003 03:24 AM

:o
Hi!
Yes, musrum, you were absolutely right!
I misunderstood you; the first time you told I had to type
Code:

bind '"\nnn": self-insert'
I understood "self-insert" as the result of typing the key associated with \nnn...
Thank you very much!
:)
Regards

dazdaz 11-04-2003 05:37 AM

musrum :

$ bind -x '"H": "echo hello"'
hello
$ echo $?
0


Yes that works for the H key... although I still hav'nt got any further in figuring out why the function keys don't bind in bash.

I'm using Putty 0.53b on an IBM ThinkPad.

Regards


All times are GMT -5. The time now is 08:24 PM.