[NTLUG:Discuss] hotkeys

Patrick R. Michaud pmichaud at pobox.com
Sat Jun 23 10:42:54 CDT 2012


[From a request during a previous NTLUG meeting.]

I'm a huge fan of keyboard shortcuts; for common operations
it's far faster for me to hit a key combination on the keyboard
than it is to find the mouse, navigate to a menu, press a mouse
button, navigate to a submenu, press a mouse button, etc.
These are commonly called "hotkeys".

Some window managers come with hotkey support built in; for a long
time I used KDE's hotkey support.  This works fine, but configuring
the hotkeys requires manually going through and defining them all.
Also, I couldn't easily make mappings for mouse buttons.
Then I found xbindkeys.

Xbindkeys is a program that grabs keys and mouse button events in X
and starts shell commands.  It's really simple to configure, seems to
work with any window manager, and also is able to map the "extra"
mouse buttons that come with some mice.  For example, my Logitech
Anywhere Mouse MX has at least eight separate mouse button
possibilites; with xbindkeys I'm able to map each of these
individually and in combination with other buttons/keys.
In my setup, I have mouse button 8 (on the side of my mouse)
set to open a browser to the url on the clipboard; this means
I can use the mouse to drag+highlight any url on the screen
and press the side mouse button to instantly open it in a web
browser.

Using xbindkeys is quite simple -- just create a .xbindkeyrc
file with the keyboard/button mappings you want and then run
the 'xbindkeys' command (I run the command as part of my
KDE autostart process).  The format of .xbindkeysrc looks
something like:

    # Alt + t open a terminal
    "/usr/bin/xterm"
      Mod4 + t

    # Alt + b open a web browser
    "/usr/bin/firefox"
      Mod4 + b

    # Shift + Alt + b  kills all browsers
    "/usr/bin/killall firefox"
      Shift+Mod4 + b

    # F12 open a web browser to url on clipboard
    "/usr/bin/firefox $(xclip -o)"
      F12

    # Mouse button 8 (on side of mouse) opens web 
    # browser to url on clipboard
    "/usr/bin/firefox $(xclip -o)"
      b:8

Each mapping consists of a command (in double quotes) on one line with
the key/button combination to invoke that command on the next.  
In the above, "Mod4" corresponds to the "left Alt" key; "b:8" means
"mouse button 8".  xbindkeys provides a "--key" and "--multikey" 
option to make it easier to find out the specification for other 
keyboard or button presses.

For many commands I just write a simple shell script to invoke the
command I want, then have xbindkeys invoke the shell script.

Here are the keyboard shortcuts I commonly use:

    F12              open a web browser using url on clipboard
    b:8              open a web browser using url on clipboard
    Shift+Mod4+F12   open incognito web browser using url on clipboard
    Mod4+b           open a web browser to home page
    Mod4+c           open Google calendar
    Mod4+d           open Google docs
    Mod4+equal       open Google+
    Mod4+w           open weather forecast pages

    Mod4+t           open a terminal window
    Shift+Mod4+t     open a terminal window with extra-large font
                        (very useful during presentations)

    Mod4+m           open mail  (mutt)
    Mod4+i           open IRC session (irssi)

    Mod4+k           open terminal to kiwi (desktop)
    Mod4+p           open terminal to plum (laptop)
    Mod4+o           open terminal to orange (old desktop)
    Shift+Mod4+p     open terminal to pmichaud.com (webserver)

    Mod4+x           copy highlighted text to clipboard
    Shift+Mod4+x     copy highlighted text to nopaste service

For each of the last four shortcuts, they invoke a shell script
that opens a terminal window locally if I'm already on the
desired host, or opens a ssh session if the desired host is
remote.  The background color of these windows also changes (kiwi==green,
plum==plum, orange==orange, pmichaud.com==yellow) to make it easy 
for me to quickly know what machine I'm sending commands to.

Hope this is useful; if anyone has questions, send me an email!

Pm



More information about the Discuss mailing list