Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

HOWTO: Control volume without any tray mixer (i.e. kmix)

Share your HowTo, Documentation, Tips and Tricks. Not for support questions!.
Post Reply
Message
Author
User avatar
mvdan
Posts: 237
Joined: 2010-12-17 17:52
Location: Barcelona, Spain

HOWTO: Control volume without any tray mixer (i.e. kmix)

#1 Post by mvdan »

Imagine you want to control your system's Master volume (or any other channel), as you would normally do it with gnome's ALSA mixer or Kmix, but you want to save RAM or you don't want to be running those processes on the background.

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.
Last edited by mvdan on 2011-05-04 15:24, edited 5 times in total.
Unstable 'Sid' amd64 - Awesome WM - https://gitorious.org/~mvdan
Richard M. Stallman wrote:We can't take the future of freedom for granted. Don't take it for granted! If you want to keep your freedom, you must be prepared for it.

handheldCar
Posts: 221
Joined: 2009-11-27 02:31
Location: North Cackalack

Re: HOWTO: Control volume without any mixer (i.e. kmix)

#2 Post by handheldCar »

Thanks, Daniel, this inspired me to see if I could use my keyboard volume knob to change the volume as it did in KDE, and I succeeded in Fluxbox. To reproduce, you'll need to know your keyboard multimedia key codes first. That page alone may work for you, but it didn't for me; so I went to the Fluxbox key file (~/.fluxbox/keys). I found a section for "volume settings, using common keycodes", and I put in my values for raise, lower, and mute. After I restarted Fluxbox, I was very happy to see them having an effect in alsamixer. I had to change "Master" to "PCM", too. I also have keycodes for HomePage, Mail, AudioNext, AudioPlay, AudioPrev and Sleep, but I didn't see a section for them in ~/.fluxbox/keys.

User avatar
mvdan
Posts: 237
Joined: 2010-12-17 17:52
Location: Barcelona, Spain

Re: HOWTO: Control volume without any mixer (i.e. kmix)

#3 Post by mvdan »

handheldCar wrote:Thanks, Daniel, this inspired me to see if I could use my keyboard volume knob to change the volume as it did in KDE, and I succeeded in Fluxbox. To reproduce, you'll need to know your keyboard multimedia key codes first. That page alone may work for you, but it didn't for me; so I went to the Fluxbox key file (~/.fluxbox/keys). I found a section for "volume settings, using common keycodes", and I put in my values for raise, lower, and mute. After I restarted Fluxbox, I was very happy to see them having an effect in alsamixer. I had to change "Master" to "PCM", too. I also have keycodes for HomePage, Mail, AudioNext, AudioPlay, AudioPrev and Sleep, but I didn't see a section for them in ~/.fluxbox/keys.
Thanks for the heads up!
Unstable 'Sid' amd64 - Awesome WM - https://gitorious.org/~mvdan
Richard M. Stallman wrote:We can't take the future of freedom for granted. Don't take it for granted! If you want to keep your freedom, you must be prepared for it.

handheldCar
Posts: 221
Joined: 2009-11-27 02:31
Location: North Cackalack

Re: HOWTO: Control volume without any tray mixer (i.e. kmix)

#4 Post by handheldCar »

I just found this xbindkeys tutorial for other multimedia keys, and now I'm opening Icedove with the push of a button.

secipolla
Posts: 1127
Joined: 2010-06-21 14:20

Re: HOWTO: Control volume without any tray mixer (i.e. kmix)

#5 Post by secipolla »

It works fine with Openbox/LXDE.
http://openbox.org/wiki/Help:Bindings#Key_combination
For instance, mine:

Code: Select all

    <keybind key="W-KP_Divide">
      <action name="Execute">
        <execute>aumix -v -5</execute>
      </action>
    </keybind>
    <keybind key="W-KP_Multiply">
      <action name="Execute">
        <execute>aumix -v +5</execute>
      </action>
    </keybind>
There's also an app to edit keyboard shortcuts in Openbox at http://code.google.com/p/obkey/

User avatar
mvdan
Posts: 237
Joined: 2010-12-17 17:52
Location: Barcelona, Spain

Re: HOWTO: Control volume without any tray mixer (i.e. kmix)

#6 Post by mvdan »

handheldCar wrote:I just found this xbindkeys tutorial for other multimedia keys, and now I'm opening Icedove with the push of a button.
Thanks, added :)
secipolla wrote:It works fine with Openbox/LXDE.
http://openbox.org/wiki/Help:Bindings#Key_combination
For instance, mine:

Code: Select all

    <keybind key="W-KP_Divide">
      <action name="Execute">
        <execute>aumix -v -5</execute>
      </action>
    </keybind>
    <keybind key="W-KP_Multiply">
      <action name="Execute">
        <execute>aumix -v +5</execute>
      </action>
    </keybind>
There's also an app to edit keyboard shortcuts in Openbox at http://code.google.com/p/obkey/
Thanks for testing it and for the openbox tutos!
Unstable 'Sid' amd64 - Awesome WM - https://gitorious.org/~mvdan
Richard M. Stallman wrote:We can't take the future of freedom for granted. Don't take it for granted! If you want to keep your freedom, you must be prepared for it.

handheldCar
Posts: 221
Joined: 2009-11-27 02:31
Location: North Cackalack

Re: HOWTO: Control volume without any tray mixer (i.e. kmix)

#7 Post by handheldCar »

As seen on Arch Linux Forums, we can add a volume knob just by using its key name, i.e. XF86AudioLowerVolume, so this is how I did mine:

Code: Select all

    <!-- Keybindings for Volume -->
    <keybind key="XF86AudioMute">
      <action name="Execute">
        <execute>amixer set Headphone toggle</execute>
      </action>
    </keybind>
    <keybind key="XF86AudioLowerVolume">
      <action name="Execute">
        <execute>amixer set Headphone 1.5dB-</execute>
      </action>
    </keybind>
    <keybind key="XF86AudioRaiseVolume">
      <action name="Execute">
        <execute>amixer set Headphone 1.5dB+</execute>
      </action>
    </keybind>
You might have to replace "Headphone" with "Master". As for the other multimedia keys such as previous, stop, play/pause and next, they are pretty straight-forward for each program and only take a few minutes to Scroogle unless you use VLC. Based on this CrunchBang Linux Forums post, I set up my keys like this:

Code: Select all

    <!-- Keybindings for Playback -->
    <keybind key="XF86AudioPlay">
      <action name="Execute">
        <execute>wget -q -t 1 -O - http://127.0.0.1:8080/?control=pause</execute>
      </action>
    </keybind>
    <keybind key="XF86AudioPrev">
      <action name="Execute">
        <execute>wget -q -t 1 -O - http://127.0.0.1:8080/?control=previous</execute>
      </action>
    </keybind>
    <keybind key="XF86AudioNext">
      <action name="Execute">
        <execute>wget -q -t 1 -O - http://127.0.0.1:8080/?control=next</execute>
      </action>
    </keybind>
    <keybind key="XF86AudioStop">
      <action name="Execute">
        <execute>wget -q -t 1 -O - http://127.0.0.1:8080/?control=stop</execute>
      </action>
    </keybind>
Yes, you can control VLC through URLs, but first you have to set it up and restart VLC. That setting is at Tools, Preferences, All settings, Interface, Main Interfaces and HTTP remote control interface. The wget options mean quiet, one time, and write to standard output. The IP address, 127.0.0.1, is localhost of course, and the port, 8080, must be one that VLC listens on by default.

User avatar
mvdan
Posts: 237
Joined: 2010-12-17 17:52
Location: Barcelona, Spain

Re: HOWTO: Control volume without any tray mixer (i.e. kmix)

#8 Post by mvdan »

You're right, vlc seems to show no play/pause command line option neither with -h, -H or man vlc. Thanks for the heads up!
Unstable 'Sid' amd64 - Awesome WM - https://gitorious.org/~mvdan
Richard M. Stallman wrote:We can't take the future of freedom for granted. Don't take it for granted! If you want to keep your freedom, you must be prepared for it.

absitch
Posts: 1
Joined: 2014-05-12 21:51

Re: HOWTO: Control volume without any tray mixer (i.e. kmix)

#9 Post by absitch »

[POST IN REFERENCE TO FLUXBOX]

I come from a position of being new to the fluxbox keys file, as the settings out of the box generally work for me, save for the default menu. In many ways I'm still new to the windows manager. Given that the issues I ran into and how well this thread helped me resolve them I thought I would share what I ran into. In the case that someone else out there is running into the issue too.

Firstly, what are Mod keys? For more info see this page: http://fluxbox-wiki.org/index.php/Keybo ... _keys_file

Secondly, after I added the changes to the keys file with the proper amixer commands, and finding the right key combo, I was having issues getting the key combination to work. So I started clicking the reconfigure and restart commands in the fluxbox menu. Safe to say that reconfigure does the trick, whatever that trick is (most likely reloading configurations), and I was able to use the amixer commands.

TLDR; If the newly edited keys file commands do not work, make sure you have saved the file (obviously), and then in the fluxbox menu click on reconfigure button. It's probably best to click on that anyway to make sure the settings, if any, are "written to the init" file.

Post Reply