Credit portal





how to swap keys on keyboard

Xbindkeys is a very versatile program that lets you remap keys very easily. It uses a config file, my default located in your home directory, to change key bindings into certain commands.

To create a default config file you use the command:

Which prints the default config file. So if you want to create the file containing the default values you would use:

Which prints the default values into a hidden file named .xbindkeysrc located in home (

Now to actually change the bindings of keys we first need to know what the name or keysym of those keys is. xbindkeys allows us to use the -k handle to find the name of a key or key combination. Run:

And press a key or key combination. Your output will look something similar to this (when pressing space ):

"No Command" tells us that currently no command is associated with the Space key.

Is the name of the key/key combination.

the config file..

Lets open up the config file you made earlier:

Here is an excerpt from the default config file:

Every line beginning with # is a comment and won't be read or run by xbindkeys.

So far the only line that isn't commented out is:

This excerpt shows the basic syntax of xbindkeys commands:

So as you can see:

Runs the command xbindkeys_show when you press Ctrl + Shift + q.

bind keys to commands..

Now lets try binding a few keys. I recommend clearing the entire default file so that it's blank. It contains preset key bindings you probably don't want.

Now lets say you want to use Ctrl + b to open your browser. First you need to know what the name or keysym of Ctrl + b is. As mentioned earlier you can use xbindkeys -k to find the name of a key or keys, but there is an easier way. For simple combinations like Ctrl + b you can just use:

Now find the command for your favorite browser:

For Firefox: firefox

For Chromium: chromium-browser

For Opera: opera

Remember the syntax from earlier? The xbindkeys command to launch Firefox (or your other favorite browser) when you press Ctrl + b is:

Now put that in your config file and

save it. Now you might notice your command doesn't work yet, that's because xbindkeys isn't running. To start it just run xbindkeys from a terminal. Your Ctrl + b should now start your browser!

bind keys to other keys..

If you want a key on your keyboard to call a different key on your keyboard, you will need an extra piece of software as xbindkeys does not support this on it's own. I know of two programs which we can use, xdotool and xte. I prefer xte so I'm going to use that.

Install it:

The syntax for xte is like this:


To call a single key press: xte 'key keyName'

To call a key combination: xte 'keydown keyName' 'keydown secondKeyName' 'keyup keyName' 'keyup secondKeyName

To call a mouse button: xte 'mouseclick buttonNumber' (We'll discuss finding button numbers a little latter)

To move the mouse: xte 'mousemove xCoordinate yCoordinate'

And more! Read man xte

Now that you know the command for simulating key presses you can call it from your xbindkeys script, like this:

As you might guess, this calls xte 'key b' when we press Ctrl + b. which would enter a b into any document you might be currently working on.

I thing to note however is that xbindkeys and xte don't always work very well together. Sometimes you have to press the keys exactly at the same time to get output, other times it works just fine. This may or may not have to do with system configuration and/or hardware. I'm not sure. See maggotbrain's answer for a more reliable way of binding keys to other keys.

bind mouse buttons to commands..

You can also use xbindkeys to bind mouse buttons to commands (and thence keyboard shortcuts, see above). The basic format for mouse buttons should be familiar to you now:

Where [command to run] is the command you want to run and n the number of the mouse button you want to use for that command.

If you don't know the number of your mouse button you can use xev to find out what it is:

The output will be something like this:

When I press each of my mouse buttons.

For example:

Launches firefox when I press my middle mouse button.

Category: Forex

Similar articles: