Programable ShortCut Keys

Discuss Programming
Post Reply
User avatar
Basher52
guru
guru
Posts: 922
Joined: Wed Oct 22, 2003 5:57 am
Location: .SE

Programable ShortCut Keys

Post by Basher52 » Sat Oct 01, 2005 6:44 pm

Is it posible to "program" shortcuteys i Linux?
(and i DO mean in "consolemode" (but also in 'X'))

eg. I want "F2" or another key(or combination of keys) to do some sort of function that i set.
like, push "F2" and start the program 'xyz',(or script, bashscript etc etc).

is this possible?

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Sat Oct 01, 2005 7:34 pm

It's pretty easy for virtual terminals. You can actually use bash's ~/.inputrc. Create a ~/.inputrc file and put these two lines in it:

Code: Select all

"\e[[A": "echo Test\n"
"\e[[B": "ls -alp\n"
In a virtual terminal you can then press F1 and it will echo "Test". Pressing F2 will do a directory listing, etc. See /etc/inputrc for the default maps and do a "man bash" and search for inputrc for more info. Doing this in X is a little harder because not only are there X key bindings but the desktop environment also has it's own key functions. So pressing the particular function key will do whatever the DE has assigned it. If you unmap the keys in question you should be able to do it. Mind you that the F keys will send a different value in an xterm than it does in a virtual terminal. I usually use the "od" command to see what characters are actually sent by the key.

User avatar
Basher52
guru
guru
Posts: 922
Joined: Wed Oct 22, 2003 5:57 am
Location: .SE

Post by Basher52 » Mon Oct 03, 2005 1:20 am

i tried it and it sure works :D thnx

but in man bash it says this:
"\e[11~": "Function Key 1"

and u said:
"\e[[A": "echo Test\n"

so which is right? your works so i gotta be that one and not the man bash version. Is it me or has the man bash some errors?

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Mon Oct 03, 2005 8:35 am

It depends on what your keyboard map and termcap/terminfo look like as to what codes your keys actually produce. Like I said, to see what characters they are putting out just type "od -c" on the command line, press a key and then hit "CTRL+D".

Post Reply