What we'll do is use two keyboard shortcuts to Rise and Lower the Master channel (general volume), making use of the amixer command-line tool.
Step 1: What DE do you use? Do you know how to add a new keyboard shortcut?
Gnome/KDE - In preferences (or in the Control Center) you'll find the Keyboard Shortcuts configuration GUI.
Xfce - In Settings > Keyboard > Application Shortcuts you'll find the GUI.
LXDE (openbox) - You can add a line in ~/.config/openbox/rc.xml - Run: (vi/vim text editor for experienced users)
- Code: Select all
nano ~/.config/openbox/rc.xml
Fluxbox - You can add a line in ~/.fluxbox/keys - Run: (vi/vim text editor for experienced users)
- Code: Select all
nano ~/.fluxbox/keys
Step 2: Which keys are we going to use?
If we're going to use Gnome, KDE or Xfce, we don't have to worry about it. The GUI will pick up the key combination when adding the keyboard shortcut.
If we're going to use Openbox (LXDE) or Fluxbox, we'll write the key combinations manually. If we want to use a special key (apart from letters, numbers, signs and combiantion keys like Control or Shift), we can use xev. How? Just run it:
- Code: Select all
xev
And then press the button and look at the terminal output. Then look at the part that says "keycode XXX" and take note of the number.
We can also use the command showkey. More information in the Debian wiki page keyboard multimedia key codes. There's also some multimedia keys information in this tutorial.
(Note: keycodes for special keys has only been tested and proved under Fluxbox and Openbox this far; if anybody could test it under any other WM I would be very grateful)
Step 3: Adding the two new keyboard shortcuts
The two commands are going to be the same under any Desktop Environment or Window Manager.
To rise the volume (Master, by 5%)
- Code: Select all
amixer set Master 5%+
To lower the volume (Master, by 5%)
- Code: Select all
amixer set Master 5%-
Note: We can also use the Mute command with a keyboard shortcut:
- Code: Select all
amixer set Master toggle
Now, to create the two new keyboard shortcuts:
Gnome/KDE/Xfce - Add two new keyboard shortcuts as shown in step 1 and paste the two commands to execute, respectively. Enter the key or key combination that you want, by doing it when asked to do so.
Openbox (LXDE) - We'll add the two keyboard shortcuts as stated in step 1:
- Code: Select all
nano ~/.config/openbox/rc.xml
And we'll add the following: (this is the template, you'll change the keybind)
- Code: Select all
<keybind key="keybind">
<action name="Rise Master by 5%">
<command>amixer set Master 5%+</command>
</action>
</keybind>
<keybind key="keybind">
<action name="Lower Master by 5%">
<command>amixer set Master 5%-</command>
</action>
</keybind>
Note: Remember that CTRL is C, ALT is A, SHIFT is S, SUPER (or Windows) is W and to separate your keystrokes by a dash (-).
Here is an example:
- Code: Select all
<keybind key="C-S-x">
<action name="Rise Master by 5%">
<command>amixer set Master 5%+</command>
</action>
</keybind>
<keybind key="C-S-z">
<action name="Lower Master by 5%">
<command>amixer set Master 5%-</command>
</action>
</keybind>
More info about openbox keyboard shortcuts here.
Fluxbox - We'll add the two keyboard shortcuts as stated in step 1:
- Code: Select all
nano ~/.fluxbox/keys
And we'll add the following: (this is the template, you'll change the keybind)
- Code: Select all
Key1 Key2 Key3 :Exec amixer set Master 5%+
Key4 Key5 Key6 :Exec amixer set Master 5%-
Note: Remember that CTRL is Control, ALT is Mod1, SHIFT is Shift, SUPER (or Windows) is Mod4 and to separate your keystrokes by a space ( )
Here is an example:
- Code: Select all
Mod4 r :Exec amixer set Master 5%+ ## Rise master volume by 5%
122 :Exec amixer set Master 5%- ## Lower master volume by 5% (special key - using xev)
Step 4: Reboot and try it
Frequently asked questions: (will be filled up with questions asked on comments)
That's it, guys. I hope you like it. So far, this has been fully tested under Fluxbox and Openbox. If you try it under any other DE/WM and it works, please let me know. I am also open to any suggestions or corrections and improvements upon my work.