Create function keys based shortcut to speeding up work at Linux command line part # 2

by on August 31, 2005 · 3 comments· LAST UPDATED August 31, 2005

in

Under MS-Windows we all used hot function keys. Can we define hot keys under Linux? For example when I hit F1 key it should start top command or when I press F2 it should show the list of logged in users etc.
Linux comes with loadkeys utiluitity - its main purpose is to load the kernel keymap for the console. Using this utility you can modify the behavior of keys. For example when you hit F1 it will show you top command i.e. re-define keyboard action.

(A) Dump keyboard translation tables (get existing key combination on screen)
# dumpkeys

Better store it to file so that it can be modified and reloaded with loadkeys:
# dumpkeys /root/mykeys

(B) Forcing F1 key to run top command:

i) Open the file mykeys (as saved above by dumplkeys) in vi text editor:
# vi /root/mykeys

ii)Look for line string F1 = "33[[A" change it
Replace
string F1 = "33[[A"
With
string F1 = "top\n"

iii)Save the file

iv)Load the new keyboard translation tables :
# looadkeys /root/mykeys

v) Hit F1 key to see top command in action.

This way you can customize all your special key to automate task and speed up your work. You can even load custom shell script. See Speeding up work at Linux command line # part 1. Read man pages of
* loadkeys
* dumpkeys
* showkey ( displays to standard output (screen) either the scan codes, the keycode, or the character of each key pressed/released under Linux)

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 3 comments… read them below or add one }

1 james December 26, 2005 at 2:07 pm

Extra handy tip – thank you!

My webserver lives in our kitchen, and I wanted to find a way that my family could press a button and play an on-line radio station – this does it perfectly!

Reply

2 David Ramirez March 14, 2012 at 2:59 pm

Hi – this worked for my on the virtual ttys (non graphic Linux console), but I can’t get it to work on Gnome Terminal – is there any other way ?

Reply

3 vijay December 23, 2013 at 4:24 pm

sir plz help me
i want key mapping. if i press F2 key then generate file
how is it possible

Reply

Leave a Comment

Previous post:

Next post: