This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new Linux.com!

Linux.com

Feature

Start programs like a pro with XBindKeys

By Joe 'Zonker' Brockmeier on January 16, 2007 (8:00:00 AM)

Share    Print    Comments   

Desktop environments like KDE and GNOME make it possible for you to assign keyboard shortcuts to a number of global operations, but don't make it easy to create shortcuts to run any program you'd like. To set up shortcuts for programs, XBindKeys is the way to go.

XBindKeys, as the name implies, binds keys to a command. It runs in the background and waits for you to run a shortcut that's defined in its configuration file. It handles virtually any key press (not just the modifier keys that your window manager recognizes) and is easy to set up.

Getting started with XBindKeys

I'm running XBindKeys on Ubuntu and Debian, which provide XBindKeys packages. Just run apt-get install xbindkeys xbindkeys-config as root, or using sudo, and you should be off to the races. Fedora Core 6 users (and possibly earlier versions) can run yum install xbindkeys to install XBindKeys -- though Fedora doesn't include the XBindKeys Config utility we'll talk about in a moment. If you're running Solaris, see the XBindKeys site for source and packages.

Figure 1: XBindKeys Config
XBindKeys Config - click to view

After installing XBindKeys, you'll need to generate a configuration file. The easiest way to do this is by running xbindkeys --defaults > $HOME/.xbindkeysrc, or just copying one of the example configuration files from /usr/share/doc/xbindkeys/examples to .xbindkeysrc under your home directory, if you're on a Debian or Ubuntu system.

With XBindKeys you have two ways to customize your configuration -- by hand-tweaking the configuration with a text editor, or by using the XBindKeys Config GUI utility. Let's take a look at the configuration format, and then we'll cover setting up commands using the GUI utility.

The basic syntax is very simple:

#Comment about the entry
"command"
Modifier + key

The first line is pretty obvious -- that's a comment that explains what the entry is. The comment is optional, but recommended. The second line includes the command you'd like to run when you use the shortcut. Finally, the third line provides the shortcut itself.

One of the nice things about XbindKeys, versus setting shortcuts in KDE or GNOME, is that you can also use mouse buttons in a shortcut. For instance, if you wanted to use Control plus the third mouse button to launch a program, you could use this entry:

#Mouse plus control launches gaim
"gaim"
Control + b:3 + Release

XBindKeys also accepts raw keycodes. If you wanted to use Ctrl-Shift-m to open an xterm, you could add it to the config file like this:

#Using keycodes
"xterm"
m:0x5 + c:58

The first part of the entry, m:0x5 is the modifier key -- in this case Ctrl and Shift pressed together. If you just press the Shift key, it would be m:0x1, and the Control key by itself would be m:0x4. The second part, c:58, is m by itself.

What if you don't know the keycode for a key or key combination? No problem. Run xbindkeys -k from a terminal (you'll need to see its output), and it will display a small dialog box. Make sure that box has focus, and press the key or keys that you want to get the output for. Let's say you press Ctrl-Shift-h; xbindkeys will provide output that's ready to cut and paste into your .xbindkeysrc, like this:

Press combination of keys or/and click under the window.
You can use one of the two lines after "NoCommand"
in $HOME/.xbindkeysrc to bind a key.
"NoCommand"
    m:0x15 + c:43
    Control+Shift+Mod2 + h

Now all you have to do is provide the command to be run in place of "NoCommand", reload xbindkeys, and you're ready to go.

If you prefer to go the GUI route, you can use the XBindKeys Config utility. Run xbindkeys-config and you'll see a window similar to Figure 1. Make sure that you've created a configuration file first or the utility will crash when you try to save your settings.

On the left side, you'll see all of the existing shortcuts. On the right side you can see the shortcut editor. At the bottom is the toolbar for working with existing shortcuts. Let's create a new shortcut by pressing New.

Now you'll see a new entry in the shortcuts pane, and the cursor will be placed in the Name field on the right side. Give the new shortcut a name, then press the Get Key button to assign a shortcut to the action. After you've assigned a shortcut, add the command you want to run to the Action field. Once you're happy with everything, click the Apply key and try out your shortcut. XBindKeys should run your command when you press the shortcut.

One thing to watch out for -- if you've assigned a shortcut that's already in use, you may not get the results you expect. I've tried assigning a number of shortcuts that conflict with global shortcuts that are already assigned under KDE. If that happens, you'll either need to change the shortcut, or reconfigure KDE's shortcuts.

After you've set up your shortcuts you can click the Save & Apply & Exit button and start using them. However, you need to restart xbindkeys anytime you modify its configuration file -- it won't re-read the configuration automatically. I usually just use killall -HUP xbindkeys.

Also, xbindkeys needs to be running in the background to work, so you will want to make sure it runs when X starts. The best way to do this, as long as you're logging in via KDM or GDM, is to put xbindkeys in your ~/.bashrc file.

With a little work up front, XBindKeys can make your life a lot easier. Give it a try and you'll be hooked in no time.

Share    Print    Comments   

Comments

on Start programs like a pro with XBindKeys

Note: Comments are owned by the poster. We are not responsible for their content.

KDE Keyboard Shortcuts Are Easy

Posted by: Anonymous Coward on January 16, 2007 06:13 PM
What's so hard about setting up keyboard shortcuts in kde. In kde control center go to Accessibility>Keyboard Shortcuts>Command Shortcuts. It doesn't get much easier.

#

But XBindKeys is universal

Posted by: Anonymous Coward on January 16, 2007 07:40 PM
You can use the same shortcuts with every desktop/windows manager without reconfiguring each of them if you want to change environment.

#

Re:KDE Keyboard Shortcuts Are Easy

Posted by: Anonymous Coward on January 16, 2007 07:47 PM
Not a question about hard to do, was it? Command needs to be in K-menu to be accessed with shortcuts the KDE-way. Could be some work if there are a lot of command line commands with arguments to take care of. XBindKeys offer a possibility to bind arbitrary commands to shortcuts. And you don't need to use KDE if you don't like it. XBindKeys is an X11 app.

#

Re:KDE Keyboard Shortcuts Are Easy

Posted by: Anonymous Coward on January 16, 2007 07:54 PM
KDE allows for artibrary commands as well:

Accessibility > Input Actions > New Action

And then set the Action to any Command or URL you want.

It isn't universal in the way XBindKeys is, so if you switch desktops a lot XBindKeys would definitely be the way to go.

Being a fairly typical desktop user though, I don't switch desktops much. All of my most commonly used apps are launched from keypresses (including some terminal scripts that I never see the output from but do their jobs nicely).

#

Re:KDE Keyboard Shortcuts Are Easy

Posted by: Administrator on January 17, 2007 02:59 AM
You said:

"Not a question about hard to do, was it?"

FTA, the first line in fact:

"Desktop environments like KDE and GNOME make it possible for you to assign keyboard shortcuts to a number of global operations, but don't make it easy to create shortcuts to run any program you'd like."

So yes, it was a question about "hard to do."

#

I don't get it

Posted by: Anonymous Coward on January 16, 2007 08:25 PM
I can do this already with fluxbox. From the comments above it looks like you can do it with KDE as well. Granted, I can't import my keybindings from fluxbox into another window manager or DE, but how often do you switch?

Really, if you need to hop back and forth between window managers you're either using the wrong window managers for your needs, or you're not configuring them adequately.

#

Re:I don't get it

Posted by: Anonymous Coward on January 17, 2007 03:43 PM
Not all employees are allowed to use their favourite linux desktop at work if they are allowed to use linux at all. Maybe you get it now?

#

Re:I don't get it

Posted by: Anonymous Coward on January 19, 2007 12:55 AM
If they are not allowed to use Linux, it's a moot point now isn't it?

#

Well

Posted by: Anonymous Coward on January 16, 2007 08:32 PM
It could be done several ways in Gnome, KDE, Fluxbox, even Beryl has its own way to set keyboard shortcuts. But XBindKeys is great - it's easy, fast and you quicly forget that you are using it<nobr> <wbr></nobr>;).

#

No problem with shortcuts in Gnome

Posted by: Anonymous Coward on January 16, 2007 08:39 PM
Also in Gnome you can easily set up shortcuts to run various commands. Although there is no special screen in settings menu for it, you can do it in the gconf-editor, in metacity section. You are allowed to specify there up to 13 shortcuts to run commands.

#

Re:No problem with shortcuts in Gnome

Posted by: Anonymous Coward on January 17, 2007 04:02 AM
For italian people there is a little howto for gnome and metacity keybindings :

<a href="http://www.spcnet.it/areac/flatpress/index.php?entry=entry070116-184749" title="spcnet.it">http://www.spcnet.it/areac/flatpress/index.php?en<nobr>t<wbr></nobr> ry=entry070116-184749</a spcnet.it>

#

great program

Posted by: Anonymous Coward on January 17, 2007 02:49 AM
Really. I'm using it since about two years now. My window manager (ion3) has no own configuration for shortcuts, thus xbindkeys is really great, and uses much less ressources than any other similar application. And because it is completely independant from any desktop environment or window manager your configurations can easily be used on any other system. I love it.

#

Hmm

Posted by: Anonymous Coward on January 17, 2007 04:54 AM
I think that the program on the screenshot looks ugly, look at its scrollbar, it looks so ugly, like 1993 or 1994 software.

It's nice with some hotkeys. xterm on hotkey is very nice.<nobr> <wbr></nobr>:)
Web browser and calculator on hotkey can be nice too.<nobr> <wbr></nobr>:)

I think that it should autodetect some hotkeys and put them so I don't have to define them myself. On my keyboard I have button for webbrowser, email, calculator. It has mute button too and volume control.

#

Xfce

Posted by: Anonymous Coward on January 17, 2007 09:17 AM
Xfce has a pretty straight-forward way of setting custom keyboard shortcuts. I find xbindkeys to be useful in making the most of my Logitech mouse though.

#

Sawfish allows it, too

Posted by: Administrator on January 17, 2007 02:54 AM
Launch "sawfish-ui", click the Bindings tab, then "Add". In the "Command" list, click "Run shell command", grab a keystroke to use (watch for collisions!), give it the command to launch. Voila!

#

Start programs like a pro with XBindKeys

Posted by: Anonymous [ip: 76.195.82.155] on July 24, 2007 06:52 PM
How does a person install this on Ubuntu using the tar.gz?
It seems that using a Live-CD with ./configure doesn't work.

#

Start programs like a pro with XBindKeys

Posted by: Anonymous [ip: 83.83.15.167] on March 05, 2008 03:08 AM
Instead of placing xbindkeys in ~/.bashrc, one might want to put in ~/.xsession, ~/.xinitrc or ~/.xsessionrc (only the latter works for me, Debian)

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya