(Click the photo for better resolution in Picasa Photostream)
In Ubuntu 11.10 Oneiric Ocelot it is pretty easy to add a custom shortcut. Just clink the icon on the upper right of the screen, then System Settings > Keyboard > Shortcuts > Custom Shortcuts ( I'm not sure if this names are exact since my Ubuntu is in portuguese, but it should be something like this ). Then you just have to click the "+" to add a new shortcut, name it and write it's command. After that, apply and then define the keypresses that will call such command. As an example, I defined a shortcut named Banshee which calls the command "banshee" when I press Shift+F4.

Pretty easy, right? However, if you use desktop effects you won't be able to add a shortcut that runs a script the same way, since metacity is not your window manager. Compiz is.
The alternative option would be to fire up gconf-editor and add the command directly under apps >  metacity > keybinding_commands and apps > metacity > global_keybindings. However, it doesnt't work either. Why? Again, because metacity is not your window manager if you use desktop effects.
So, how to do it? First you have to install the Compiz Config Settings Manager. Launch a terminal ( default keyboard shortcut for launching the terminal is Ctrl+Alt+T ) and run
sudo apt-get install compizconfig-settings-manager
After installing, run
ccsm
Then you just have to click the "Commands" icon in the General section, define the command in the "Commands" tab and the shortcut to launch it in the "Shortcut Keys" tab and that's it.
As an example, if you wanted to create shortcut keys to control your computer's volume just like the multimedia keys you could use
xdotool key XF86AudioLowerVolume
to lower the volume and
xdotool key XF86AudioRaiseVolume
to raise your volume. Note that if you don't have xdotool installed on your computer you need to install it first
sudo apt-get install xdotool
Xdotool is a tool that let's you simulate keyboard input and mouse activity, move and resize windows, etc. It was developed as a command line X11 automation-tool. For more information check the xdotool project on semicomplete.



Did you find this post helpful? Do you wish to contribute to other projects regarding computer science, electronics, robotics or mechatronics that will be posted in this blog? If you wish to do so, you can donate via paypal using the button below. Thanks! :)

Donate

12 comments:

  1. Excellent article!
    It is just what I was looking for.
    Thanks

    ReplyDelete
  2. Thanks! I'm glad it helped!

    ReplyDelete
  3. I did all the steps, and it won't work for me. If I type "xdotool key XF86AudioLowerVolume
    " in a terminal it works just like I want it to. But it won't work when I set it up in Compiz. To test, I changed the command to "gedit" and it brings up that text editor. It seems to be an issue with XF86AudioLowerVolume.

    These work:
    Command 0: gedit
    Command 0: xdotool exec gedit

    This doesn't:
    Command 0: xdotool key XF86AudioLowerVolume

    All three of these lines execute in the terminal. Do you have any clues as to why this won't work?

    ReplyDelete
  4. Hi! Which keys did you assign the shortcuts to? I remember that for some reasons some keys didn't work.

    ReplyDelete
  5. Shift+F11, and I tried other key combinations, as well.

    It works for "gedit" and "xdotool exec gedit".

    ReplyDelete
  6. Can you try Alt+F11? I have it like that and it works

    ReplyDelete
  7. I hope this comment goes in the right place.

    OK, Alt+F11 works. I thought I tried that one. I guess not.

    I figured out what the problem is. I'm using an external keyboard with my laptop, but forget about that for the moment. I was basically trying to replicate the combo of fn+F11. However, if you hold Ctrl while also holding fn+F11, it doesn't lower the volume. If you hold Alt while also holding fn+F11, it will lower the volume. So, I guess Ctrl was getting in the way.

    I don't fully understand how the "fn" key works. It doesn't register when using something like xmacrorec, so I'm thinking it is a hardware thing....I don't know.

    Now I'm just wondering how often Alt is used at the same time as a Function key. I don't want to override a command I encounter in the future...

    Thanks for the suggestion!

    ReplyDelete
  8. That's exactly what happened to me some time ago. I also use an external keyboard with my laptop and the only key I got to work was with Alt. So far I haven't encountered any problems or conflicts with other shortcuts and I've been using this setup for a long time now. Thanks for your comments ;)

    ReplyDelete
  9. I can create the shortcut under settings but it says disabled beside it how do I make it active?

    ReplyDelete
  10. Hi! Just click on "disabled" and it will be asking for the desired key combination :)

    ReplyDelete
  11. I'm running ccsm in Ubuntu 12.10. I don't have a Commands icon in the General section. It was there in 12.04. Any suggestion on what to do now?

    ReplyDelete
    Replies
    1. Hi! Im currently running Ubuntu 12.04 LTS (upgraded from 10.10) and ccsm and I've just checked that I have the Commands option under General. you should have it too.. :\ Try to reinstall ccsm, maybe?

      Delete

top