
| Start programs like a pro with XBindKeys | |||
| 摘自: linux.com 被阅读次数: 830 | |||
由 yangyi 于 2007-02-09 22:11:28 提供 | |||
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
After installing XBindKeys, you'll need to generate a configuration file. The easiest way to do this is by running 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
#Using keycodes "xterm" m:0x5 + c:58 The first part of the entry, What if you don't know the keycode for a key or key combination? No problem. Run
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 If you prefer to go the GUI route, you can use the XBindKeys Config utility. Run 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 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 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. |