Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: [pulseaudio] volume control with multimedia keys ?

  1. #1
    Join Date
    Jul 2005
    Location
    FRANCE
    Beans
    162
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Question [pulseaudio] volume control with multimedia keys ?

    Hello,
    I have a openbox install, i search what are the command i must set for down/up/mute the volume with my multimedia key.

    Could you help me please?
    My Website : www.atlas95.com !

  2. #2
    Join Date
    Mar 2008
    Location
    Middle Tennessee
    Beans
    284
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: [pulseaudio] volume control with multimedia keys ?

    First, you may need to get your keycodes for these special keys from the xev program that will dump the X events into your terminal screen. So as you do mouse events, and keyboard events, the codes are dumped for you to see.

    Use that program to get the key events for your volume keys you want to use. It will dump output something like the following:
    Code:
    KeyPress event, serial 32, synthetic NO, window 0x2000001,
        root 0x13a, subw 0x0, time 3204054097, (867,651), root:(868,673),
        state 0x0, keycode 161 (keysym 0x0, NoSymbol), same_screen YES,
        XLookupString gives 0 bytes:
        XmbLookupString gives 0 bytes:
        XFilterEvent returns: False
    
    KeyRelease event, serial 32, synthetic NO, window 0x2000001,
        root 0x13a, subw 0x0, time 3204054097, (867,651), root:(868,673),
        state 0x0, keycode 161 (keysym 0x0, NoSymbol), same_screen YES,
        XLookupString gives 0 bytes:
        XFilterEvent returns: False
    In this case, you see that the "keycode" is 161

    Then (assuming openbox matches fluxbox in this matter) add the events to your keys file that contains your desired keyboard shortcuts.

    In that case, for my system, 161 matches the calculator special key, so I have added the following entry to my keys file:
    Code:
    None 161 :Exec xcalc
    You can execute any command line audio commands, such as alsa-mixer or what not.

    I am not at my Linux box at the moment (I am on a short break at work), so I cannot be more specific at the moment, but I can check back on this thread later today if you have tried this and still have problems.
    Linux Genuine Advantage: I am licensed!

    Spouting mindless hatred of all things Microsoft since... ummm... never.

  3. #3
    Join Date
    Jul 2005
    Location
    FRANCE
    Beans
    162
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: [pulseaudio] volume control with multimedia keys ?

    Hi,
    thanks for your help, could you help me to find what is the command to launch for set pulse volume, with command such as pacmd, pactl or whatever... I doesn't want to use alsamixer volume
    My Website : www.atlas95.com !

  4. #4
    Join Date
    Jun 2006
    Location
    $ pwd _
    Beans
    3,999
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: [pulseaudio] volume control with multimedia keys ?


  5. #5
    Join Date
    Jul 2005
    Location
    FRANCE
    Beans
    162
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: [pulseaudio] volume control with multimedia keys ?

    Thanks but isn't the method to bind my multimedia keyboard that i search, but what is the command to attribute to set the PULSEAUDIO volume kpkeerthi
    My Website : www.atlas95.com !

  6. #6
    Join Date
    Mar 2008
    Location
    Middle Tennessee
    Beans
    284
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: [pulseaudio] volume control with multimedia keys ?

    Quote Originally Posted by atlas95 View Post
    Thanks but isn't the method to bind my multimedia keyboard that i search, but what is the command to attribute to set the PULSEAUDIO volume kpkeerthi
    Unfortunately, you have caught me at work again.

    I can see pulseaudio documentation here: http://www.pulseaudio.org/wiki/CLI
    But I can see an absolute setting, and not a +5% type of adjust that I am used to in alsa.

    I haven't looked at keytouch, except to follow kpkeerthi's link, and not sure I would agree that an outside app would be better than using the native *box support.

    (p.s. I see that Openbox uses a different keybinding system than fluxbox, so my example earlier will not apply, and you must use the openbox xml file that you are probably already familiar with)
    Linux Genuine Advantage: I am licensed!

    Spouting mindless hatred of all things Microsoft since... ummm... never.

  7. #7
    Join Date
    Oct 2009
    Beans
    2

    Re: [pulseaudio] volume control with multimedia keys ?

    I managed to increase/decrease the volume of my pulseaudio with the following scripts.
    Maybe they'll be of some use for other people:

    vol+
    Code:
    #!/bin/bash
    
    A=`pacmd dump | grep "set-sink-volume alsa_output.pci-0000_00_1b.0.analog-stereo" | cut -d " " -f 3`
    B=$((A + 0x01000))
    if [ $(($B)) -gt $((0x10000)) ]
     then
        B=$((0x10000))
    fi
    pactl set-sink-volume 0 `printf "0x%X" $B`
    vol-
    Code:
    #!/bin/bash
    
    A=`pacmd dump | grep "set-sink-volume alsa_output.pci-0000_00_1b.0.analog-stereo" | cut -d " " -f 3`
    B=$((A - 0x01000))
    if [ $(($B)) -lt $((0x00000)) ]
     then
        B=$((0x00000))
    fi
    pactl set-sink-volume 0 `printf "0x%X" $B`
    mute
    Code:
    #!/bin/bash
    
    A=`pacmd dump | grep "set-sink-mute alsa_output.pci-0000_00_1b.0.analog-stereo" | cut -d " " -f 3`
    if [ $A = "no" ]
    then
        pactl set-sink-mute 0 yes
    else
        pactl set-sink-mute 0 no
    fi

  8. #8
    Join Date
    Oct 2008
    Beans
    4
    Distro
    Xubuntu 8.04 Hardy Heron

    Re: [pulseaudio] volume control with multimedia keys ?

    The above scripts didn't work for me; they set the volume to a absolute levels instead of raising/lowering it.

    The following zsh one-liners work great:

    Volume up:
    Code:
    pacmd set-sink-volume 0 $(printf '0x%x' $(( $(pacmd dump|grep set-sink-volume|cut -f3 -d' ') + 0xf00)) )
    Volume down:
    Code:
    pacmd set-sink-volume 0 $(printf '0x%x' $(( $(pacmd dump|grep set-sink-volume|cut -f3 -d' ') - 0xf00)) )
    Mute:
    Code:
    pacmd set-sink-mute 0 $(if [ $(pacmd dump |grep set-sink-mute | cut -f 3 -d' ') = 'no' ]; then echo yes; else echo no; fi;)
    Working well in my .awesomerc with zsh -c in front, should work fine in openbox configs as well.

  9. #9
    Join Date
    Dec 2010
    Beans
    1

    Re: [pulseaudio] volume control with multimedia keys ?

    Another script. Universal, based on AWK:

    Volume up:

    Code:
    pacmd dump|awk --non-decimal-data '$1~/set-sink-volume/{system ("pacmd "$1" "$2" "$3+1000)}'
    Volume down:

    Code:
    pacmd dump|awk --non-decimal-data '$1~/set-sink-volume/{system ("pacmd "$1" "$2" "$3-1000)}'
    Mute:

    Code:
    pacmd dump|awk --non-decimal-data '$1~/set-sink-mute/{system ("pacmd "$1" "$2" "($3=="yes"?"no":"yes"))}'

  10. #10
    Join Date
    Jan 2009
    Beans
    3

    Re: [pulseaudio] volume control with multimedia keys ?

    Extending those one-liners, adding the ability to jump larger increments and avoiding wrapping the volume to something huge when reducing (ouch!):

    Code:
    #!/bin/bash
    [[ $0 == pa_vol_down ]] && _down=true 
    [[ $1 ]] && let _vol_increment=$1*655 || _vol_increment=655
    _full_line=`pacmd dump|grep "set-sink-volume"`
    _sink_cmd=`echo $_full_line|cut -d" " -f1`
    _sink_id=`echo $_full_line|cut -d" " -f2`
    _sink_vol=`echo $_full_line|cut -d" " -f3`
    [[ $_down ]] && let _vol=$_sink_vol-$_vol_increment || let _vol=$_sink_vol+$_vol_increment
    [[ $_vol -lt 0 ]] && _vol=0
    [[ $_vol -gt 65536 ]] && _vol=65536
    pacmd $_sink_cmd $_sink_id $_vol > /dev/null
    Create two links to that script, named pa_vol_up and pa_vol_down, then they can be run without parameters to step up/down by 1% or with a single parameter to make that the step. E.g.;

    pa_vol_up 10
    pa_vol_down 15

    I'm sure there's an elegant way to extract the 3 elements of the dump and manipulate them, but I'm a bear of very little brain, so I've done my best.

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •