keyboard volume changer

Miscellaneous tools
Post Reply
Message
Author
User avatar
alexandrion
Posts: 105
Joined: Sat 19 Feb 2011, 06:45

keyboard volume changer

#1 Post by alexandrion »

here's a script i made to change the volume from the keyboard
it uses amixer to change the volume and yaf-splash to display the status

here's how it looks
Image

Image

here's the script

Code: Select all

#! /bin/bash 

if [[ $1 -eq 1  ]] 
then 
     P=`amixer sset 'Master Front' 1+ | grep 'Front Left:' | awk '{print $5}' | sed 's/\[/Master Front: /g' | sed 's/\]//g'` 
     M=`amixer sset 'PCM' 2+ | grep 'Front Left:' | awk '{print $5}' | sed 's/\[/PCM: /g' | sed 's/\]//g'` 
     yaf-splash -text "$P $M" -timeout 1 
else if [[ $1 -eq 2 ]] 
then 
     P=`amixer sset 'Master Front' 1- | grep 'Front Left:' | awk '{print $5}' | sed 's/\[/Master Front: /g' | sed 's/\]//g'` 
     M=`amixer sset 'PCM' 2- | grep 'Front Left:' | awk '{print $5}' | sed 's/\[/PCM: /g' | sed 's/\]//g'` 
     yaf-splash -text "$P $M" -timeout 1 
else if [[ $1 -eq 3 ]] 
then 
    P=`amixer sset 'Master Front',0 toggle | grep "Front Left:" | awk '{print $7}'` 
    if [[ ''$P'' == '[off]' ]] 
    then 
    P="Volume is off" 
    else 
    P="Volume is on" 
    fi 
    yaf-splash -text "$P" -timeout 1 
fi 
fi 
fi 
as you can see in my case master front and pcm control the volume so that's what i'm changing
not all cards have the same channels so you might want to check which controls change the volume by running alsamixer in a terminal and messing around there for a while, then make the changes in the script

after you're done changing what's relevant you your sound card save the script somewhere in /usr/bin and chmod +x it. mine is called ali-vol

now to bind that to the keyboad.
assuming you are running openbox go to your ~/.config/openbox/rc.xml
and in the keyboard bindings add

Code: Select all

    <keybind key="XF86AudioRaiseVolume">
      <action name="Execute">
        <command>ali-vol 1</command>
      </action>
    </keybind>
    <keybind key="XF86AudioLowerVolume">
      <action name="Execute">
        <command>ali-vol 2</command>
      </action>
    </keybind>
    <keybind key="XF86AudioMute">
      <action name="Execute">
        <command>ali-vol 3</command>
      </action>
    </keybind>
i couldn't figure out how to get the media keys working on mine so instead of the XF86 audio keys i use control-alt-shift-up for volume up, down for volume down and left / right for mute/unmute

Code: Select all

        <keybind key="C-A-S-Up">
      <action name="Execute">
        <command>ali-vol 1</command>
      </action>
    </keybind>
    <keybind key="C-A-S-Down">
      <action name="Execute">
        <command>ali-vol 2</command>
      </action>
    </keybind>
    <keybind key="C-A-S-Left">
      <action name="Execute">
        <command>ali-vol 3</command>
      </action>
    </keybind>
    <keybind key="C-A-S-Right">
      <action name="Execute">
        <command>ali-vol 3</command>
      </action>
    </keybind>
after you modified your rc.xml run

Code: Select all

openbox --reconfigure
in a terminal and assuming you didn't mess anything up while adding that the script should work and properly display changes

if anyone manages to get the media keys working please let me know

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#2 Post by disciple »

if anyone manages to get the media keys working please let me know
Usually I think people use Sven for this (search the forum for a package). At least they used to, anyway.
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

User avatar
alexandrion
Posts: 105
Joined: Sat 19 Feb 2011, 06:45

#3 Post by alexandrion »

upon reading your post i decided to give sven a try but unfortunately it failed to detect the buttons (just like xev)
thanks anyway :D

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#4 Post by 8-bit »

I have a Compaq PC with volume adjustment keys on the keyboard and they work in Lupu 520.
If you have the tray volume slider up, the display does not change when the keyboard associated keys are pressed.
But if you exit the volume slider adjustment and reopen it, the volume will have been changed as per the keyboard volume keys.

User avatar
alexandrion
Posts: 105
Joined: Sat 19 Feb 2011, 06:45

#5 Post by alexandrion »

actually retrovol was the first thing i removed when i got here,
my problem is that xev doesn't notice when i press the media keys, anyway,i can live without them :)
this thread is more about the script anyway

User avatar
CatDude
Posts: 1563
Joined: Wed 03 Jan 2007, 17:49
Location: UK

#6 Post by CatDude »

Hello alexandrion
alexandrion wrote:...my problem is that xev doesn't notice when i press the media keys,
Maybe this will help, it describes how i got all 23 keys working on my keyboard.

CatDude

P.S
If you cannot get hold of a copy of setkeycodes
let me know and i will post the one i am using.
.
Attachments
keys.pdf.gz
Updated because i noticed a typo
(45.14 KiB) Downloaded 635 times
Last edited by CatDude on Tue 26 Apr 2011, 15:37, edited 1 time in total.
[img]http://www.smokey01.com/CatDude/.temp/sigs/acer-futile.gif[/img]

User avatar
alexandrion
Posts: 105
Joined: Sat 19 Feb 2011, 06:45

#7 Post by alexandrion »

the keys don't get logged as inexistent ...

Post Reply