LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-30-2003, 04:23 AM   #1
dazdaz
Member
 
Registered: Aug 2003
Location: Europe
Distribution: RHEL, CentOS, Ubuntu
Posts: 333

Rep: Reputation: 17
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
 
Old 10-30-2003, 07:07 AM   #2
dazdaz
Member
 
Registered: Aug 2003
Location: Europe
Distribution: RHEL, CentOS, Ubuntu
Posts: 333

Original Poster
Rep: Reputation: 17
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!
 
Old 10-30-2003, 08:25 AM   #3
dazdaz
Member
 
Registered: Aug 2003
Location: Europe
Distribution: RHEL, CentOS, Ubuntu
Posts: 333

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

bind -x "\x59" "echo hello"
 
Old 10-30-2003, 09:36 AM   #4
guygriffiths
Member
 
Registered: Jun 2003
Location: Reading, UK
Distribution: Debian 3.0, LFS
Posts: 524

Rep: Reputation: 37
Sounds like you're 99% of the way there. Put the commands in ~/.bash_profile if you want them all of the time.
 
Old 10-31-2003, 04:45 AM   #5
dazdaz
Member
 
Registered: Aug 2003
Location: Europe
Distribution: RHEL, CentOS, Ubuntu
Posts: 333

Original Poster
Rep: Reputation: 17
Nope I still can't figure this out. Can anybody help? Thanks
 
Old 10-31-2003, 06:34 AM   #6
guygriffiths
Member
 
Registered: Jun 2003
Location: Reading, UK
Distribution: Debian 3.0, LFS
Posts: 524

Rep: Reputation: 37
What's the problem? What does bind do? Try looking for help about "alias", that should also do the trick
 
Old 10-31-2003, 07:15 AM   #7
musrum
Member
 
Registered: Oct 2003
Distribution: Slackware
Posts: 112

Rep: Reputation: 15
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
 
Old 10-31-2003, 09:36 AM   #8
dazdaz
Member
 
Registered: Aug 2003
Location: Europe
Distribution: RHEL, CentOS, Ubuntu
Posts: 333

Original Poster
Rep: Reputation: 17
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
 
Old 10-31-2003, 10:50 AM   #9
musrum
Member
 
Registered: Oct 2003
Distribution: Slackware
Posts: 112

Rep: Reputation: 15
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.
 
Old 10-31-2003, 01:59 PM   #10
Y0jiMb0
Member
 
Registered: Jul 2003
Location: Valencia (Spain)
Distribution: slackware 11, FEDORA CORE 4, RHEL3, Gentoo...
Posts: 361

Rep: Reputation: 30
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
2) Where can I find the code of every key?
Regards
 
Old 10-31-2003, 02:04 PM   #11
musrum
Member
 
Registered: Oct 2003
Distribution: Slackware
Posts: 112

Rep: Reputation: 15
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.
 
Old 10-31-2003, 02:46 PM   #12
Y0jiMb0
Member
 
Registered: Jul 2003
Location: Valencia (Spain)
Distribution: slackware 11, FEDORA CORE 4, RHEL3, Gentoo...
Posts: 361

Rep: Reputation: 30
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)
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
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?
Any idea?
Regards
 
Old 11-01-2003, 08:42 AM   #13
musrum
Member
 
Registered: Oct 2003
Distribution: Slackware
Posts: 112

Rep: Reputation: 15
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'
 
Old 11-02-2003, 02:24 AM   #14
Y0jiMb0
Member
 
Registered: Jul 2003
Location: Valencia (Spain)
Distribution: slackware 11, FEDORA CORE 4, RHEL3, Gentoo...
Posts: 361

Rep: Reputation: 30

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
 
Old 11-04-2003, 04:37 AM   #15
dazdaz
Member
 
Registered: Aug 2003
Location: Europe
Distribution: RHEL, CentOS, Ubuntu
Posts: 333

Original Poster
Rep: Reputation: 17
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding special function keys? jnsg Slackware 2 09-06-2005 09:13 PM
Could not access keyboard function keys( F1, F2 etc...) wallwaters Programming 0 08-30-2005 07:17 PM
Using Function Keys with SSH bad_andy Linux - Networking 3 01-26-2005 06:41 PM
function keys laptop legolin Linux - Laptop and Netbook 1 11-27-2004 07:37 PM
Function Keys under Redhat 9 nick81 Linux - Software 0 03-08-2004 12:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration