Sunday, March 1, 2009

OpenBox - Setup Laptop Volume Keys

First you need to verify that your keys are mapped properly.

Run xev and press each of the volume keys:

Example:
   $ xev
Volume Down Results
   KeyRelease event, serial 32, synthetic NO, window 0xc00001,
      root 0x7d, subw 0x0, time 100213680, (-194,56), root:(229,367),
      state 0x0, keycode 122 (keysym 0x1008ff11, XF86AudioLowerVolume),
Volume Up Results
   KeyRelease event, serial 35, synthetic NO, window 0xc00001,
      root 0x7d, subw 0x0, time 100214182, (-194,56), root:(229,367),
      state 0x0, keycode 123 (keysym 0x1008ff13, XF86AudioRaiseVolume),
Volume Mute Results
   KeyRelease event, serial 35, synthetic NO, window 0xc00001,
      root 0x7d, subw 0x0, time 100214715, (-194,56), root:(229,367),
      state 0x0, keycode 121 (keysym 0x1008ff12, XF86AudioMute),
The keycodes are required if you are planning to use programs such as xbindkeys and raw keycodes. For OpenBox in CrunchBangLinux I did not need to install another package. I simply had to configure the OpenBox rc.xml file using the following key names:

XF86AudioLowerVolume, XF86AudioRaiseVolume and XF86AudioMute

Here's how:

Open file ~/.config/openbox/rc.xml with your favourite editor.
   $ nano ~/.config/openbox/rc.xml
Find </keyboard>

Example:
   ... 
    <keybind key="A-C-q">
      <action name="ShowMenu">
        <menu>root-menu</menu>
      </action>
    </keybind>
  </keyboard>
Paste in the following lines between </keybind> and </keyboard>.
   <keybind key="XF86AudioRaiseVolume">
    <action name="Execute">
      <execute>amixer set Master 1+</execute>
    </action>
  </keybind>
  <keybind key="XF86AudioLowerVolume">
    <action name="Execute">
      <execute>amixer set Master 1-</execute>
    </action>
  </keybind>
  <keybind key="XF86AudioMute">
    <action name="Execute">
      <execute>amixer set Master toggle</execute>
    </action>
  </keybind>
Save and reload the configuration from Menu -> Preference -> Openbox Config -> Restart

2 comments:

  1. Maybe this will help someone:

    On my Arch, 'amixer set Master 1-' or 'amixer set Master 1+' doesn't work. (@dalekleader: you got an error on your code, you got double 's' in set Master)

    What I did to make it work on my Arch was:
    'amixer set Master 1%-' and 'amixer set Master 2%+'

    ReplyDelete
    Replies
    1. @Marco, it has been awhile since I wrote that I cannot even recall how I missed that. Thank you, I will fix it.

      Delete