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
string F1 = “33[[A”
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)

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 4 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
4 comments… add one
  • james Dec 26, 2005 @ 14:07

    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!

  • David Ramirez Mar 14, 2012 @ 14:59

    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 ?

    • vijay Dec 23, 2013 @ 16:24

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

  • Larry Schultz Aug 9, 2017 @ 0:38

    After years of looking for a solution to remap function keys so that my F10 key sends CTRL-D escape command to a warehouse ERP solution in telnet your article helped me figure out how to use dumpkeys / loadkeys / showkey to remap my function keys. Now I have a viable solution to replace Windows 10 / propietary paid ssh app and $3000CAD handhelds, and mobile phone with handheld scanners (which don’t work) with a Raspberry Pi and handscanner solution. Unfortunately, my work probably won’t go the Linux route. But I did it, thanks to your help.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum