8

On the computer upstairs we have an option to make the computer make a sound when we press Caps Lock, Number Lock and Scroll Lock. Is there a way to do this on Ubuntu 12.04?

8

1 Answer 1

5

Ok, so I got this to work with xbindkeys.

We will use Beep as notification sound.

To install Beep:

sudo apt-get install beep

It is necessary to enable the speaker in recent versions.

modprobe pcspkr

Ok, now for the notification script:
First make a new file, and save it as notification.sh.

Insert this piece of script(smallest script ever?):

beep

and save it.
Place it somewhere safe, for this little "tut" I will place it in /home/notification/
Now we need xbindkeys:

sudo apt-get install xbindkeys

Once it is installed, go to your home folder, and make a new file named:".xbindkeysrc".
This file is required for xbindkeys, without, it doesn't function.
Open this file with a text editor.

Now we do need the keynumbers xbindkeys requires.
To get those, open terminal, and enter:

xbindkeys -k

A windows will popup, and then you are to press the key you want the code from, eg. Capslock.

You will see something like:

in $HOME/.xbindkeysrc to bind a key. "NoCommand"
m:0x2 + c:66
Caps_Lock

Now, we only need the m:0x2 + c:66 part(might be different for you). Write those down(in a text editor or something) and repeat the process until you got all your keys.

Now, remember the xbindkeysrc we opened in the texteditor? We are going to add the following:

"bash /home/notification/notification.sh"

This line will tell what the xbindkeys has to do when certain keys are pressed. The next line we will add is the keycode(s), like this:

m:0x2 + c:66

if you want the same thing to happen with multiple keys, you must separate the keys, like this:

m:0x2 + c:66 || m:0x3 + c:67

The || means OR, this is not relevant for you.

A logout/login could be necessary to map the beep to the Caps Lock (for example).

I hope that this guide was useful for you and others.

2
  • 1
    I use xbindkeys, and by installing xbindkeys-config as well as xbindkeys there is no need for xbindkeysrc ... xbindkeysrc provides an easy to use GUI interface. Setting up the shortcut keys is particularly easy; there is no need to deal directly with all the ` m:0x3 + c:67` stuff. xbindkeys is also useful in that you have more control over the modifier keys than does the default Keyboard Shortcuts app, though that app is quite good enough unless you are a keyboard shortcuts junkie (like me).
    – Peter.O
    Dec 29, 2012 at 15:03
  • O, I didn't know that, but I do prefer knowing that code is actually used. I will update my answer, thanks.
    – Dr_Bunsen
    Dec 29, 2012 at 15:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .