The convenience of having keyboard controls for sound volume

January 9, 2016

For a long time now, many keyboards have come with various additional keys over and above the traditional set. First it was Windows keys, and then people started adding various 'multimedia' keys and buttons for things. For an equally long time I used a very minimal keyboard without such keys, so I rolled my eyes a little bit at the indulgence (and the wasted space) and otherwise ignored the issue of keyboard 'multimedia' control. Even when I recently got a keyboard that sort of had these keys, I initially kept ignoring them and the whole issue; it was easy enough to reach out to the appropriate speaker to fiddle the volume, or maybe call up the applet I have sitting there for general volume control.

It turns out that I was kind of being a fool about this (as usual). Having keys that I wasn't actually using nagged at me a bit, and recently I got just irritated enough with reaching for the volume control to figure out how to wire up these keys to do something. The first thing I learned is that it turned out to be relatively easy; there are command line tools that will let you control volume, these keys generated distinct keycodes, and they were easily bound to actions in fvwm. My current setup is:

Key XF86AudioRaiseVolume   A N   Exec amixer -q set Master '2%+'
Key XF86AudioLowerVolume   A N   Exec amixer -q set Master '2%-'
Key XF86AudioMute          A N   Exec amixer -q set Master toggle

(Some of my sources when I researched this include here, here, and here. Some of these also give the pactl equivalents of my amixer commands. See also this little GUI tool (via), although I actually use the old Gnome volume control applet from Fedora 14, which miraculously hasn't broken yet.)

When I set this up, I expected this to be basically a curio. As you may have gathered, I was wrong; the keyboard keys have rapidly become my primary method of doing volume control. It's not because they're any better than turning the volume knob or moving the volume slider up or down (in some ways they're worse). It's because they're significantly more convenient, because my hands are usually right there on the keyboard and volume shifts are thus just a quick tap away. As small as it seems, not having to reach for the volume knob or the mouse really does make a palpable difference for how things feel. Even if it's a little bit of work to shift my hand, it's less work, less interruption, and less annoyance, and I like all of that.

(The convenience of having a mute/unmute was especially a surprise. It's now trivial to mute sound if I'm watching some Youtube video just to see it, and as a result I do it fairly often.)

As a side note, I arrived at a 2% volume change per keypress partly by experimentation about what felt good and partly by observing that it's easy to rapidly repeat a keypress, so small changes were probably better than big ones. Also, I keep my sound volumes rather low so small changes in nominal volume can have clearly audible effects.

Comments on this page:

Can you use modifier keys with these?

On OS X, there's a not so secret (Option+Shift+Volumekey) that changes the volume delta per keypress to be a different percentage, which might be handy.

Nice. Here are the pulseaudio equivalents:

Key XF86AudioRaiseVolume   A N   Exec pactl set-sink-volume 0 +2%
Key XF86AudioLowerVolume   A N   Exec pactl set-sink-volume 0 -2%
Key XF86AudioMute   A N          Exec pactl set-sink-mute 0 toggle
By cks at 2016-01-19 15:15:19:

Belatedly: yes, it's possible in my window manager to define key bindings with a modifier key as well as what I have here (unmodified). As a result I've now added shifted versions that do +/- 10% instead of 2%. The syntax is just:

Key XF86AudioRaiseVolume   A S  Exec amixer -q set Master '10%+'
Key XF86AudioLowerVolume   A S  Exec amixer -q set Master '10%-'

(Here the 'S' is the difference. In fvwm, the 'A' means 'anywhere', ie regardless of where the mouse cursor or window focus is, and the 'N' or 'S' or so on is the modifier keys in effect.)

Written on 09 January 2016.
« Getting to watch a significant spam campaign recently
Updating software to IPv6 is often harder than you might think »

Page tools: View Source, View Normal, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Sat Jan 9 00:09:54 2016
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.