# laptop volume buttons to function at console

## mizery de aria

I'd like to be able to use my laptop's volume control buttons to adjust the volume of my laptop using amixer.  I can configure X appropriately for such tasks/behaviors, however, I'm uncertain as to how to do so at a console/terminal.  Any suggestions or ideas?

----------

## BlinkEye

i guess you tried without configuring anything?! i thought that usually such buttons are controlled by the hardware itself, at least my buttons and even suspend to ram are controlled this way. all i had to do was disabling ACPI and using APM. so, i set my volumes in alsamixer to maximum power but change the volume with these keys (they don't affect the alsamixer volume settings).

----------

## mizery de aria

Someone suggested I do this...

 *Quote:*   

> I stopped acpid
> 
> ```
> /etc/init.d/acpid stop
> ```
> ...

 

however I had already determined that the following captures the volume button presses...

```
cat /dev/input/event2
```

and I had already determined the keycodes of the keypresses

```
showkey

kb mode was XLATE

press any key (program terminates 10s after last keypress)...

keycode  28 release

#Pushing decrease volume button results in

keycode 114 press

keycode 114 release

#Pushing mute volume button results in

keycode 113 press

keycode 113 release

#Pushing increase volume button results in

keycode 115 press

keycode 115 release
```

/usr/share/keymaps/i386/qwerty/defkeymap.map.gz contains:

```
...

keycode  59 = F1               F13              Console_13

keycode  60 = F2               F14              Console_14

...

keycode 113 = F13

keycode 114 = F14

keycode 115 = Help

...

string F13 = "\033[25~"

string F14 = "\033[26~"

...
```

Any ideas on what to do from here?

----------

## mizery de aria

hrmm, with the default config as is (as documented above) I have noticed that at a console/terminal pushing the volume decrease button results in a "~" being printed (but appended as input to be executed...not inputted or executed as a command)...same applies when the volume mute button is pushed.  However nothing happens when the volume increase is pushed.

However the reason for that is because there is no line in /usr/share/keymaps/i386/qwerty/defkeymap.map.gz such as

```
string Help = "echo hi"
```

in which if there were a line then "echo hi" would be appended to the console awaiting for further input...but alas, not executed as a command like I want it to...

Just a note, I did the following to realize what I mentioned above:

```
#create a file such as /tmp/keymap

#add the following lines to /tmp/keymap where keycode 115 is for a particular button you are pushing (in my case it's my volume increase button)

keycode 115 = VolInc

string VolInc = "echo hi"

#save then exec the following line

loadkeys /tmp/keymap

#then push the button and you'll see what I mean...
```

Basically, I need to determine how to have such values for the strings become executable when the button is pushed... Any suggestions on that?

----------

## mizery de aria

yay..twas a simple solution after all...

/tmp/keymap:

```
keycode 113 = F13

keycode 114 = F14

keycode 115 = Help

string F13 = "echo volume mute button pushed\n"

string F14 = "echo volume decrease button pushed\n"

string Help = "echo volume increase button pushed\n"
```

then exec the following:

```
loadkeys /tmp/keymap
```

Then simply push your buttons...however one thing I noticed is that scrolling back through previous commands includes such string values from each button press...eh, oh well...and yes, don't forget to change the string values to whatever yuo desire

Also, it'd be nice to have better keysyms to use, but alas I'm not sure of any that are related to volume control buttons...

----------

## mizery de aria

actually, my solution isn't really a solution after all since when at a terminal I must be logged in and not having any program running...

Is it possible to have buttons execute a program beyond at the terminal/console?

----------

## Remenic

I almost opened a new topic on this very issue. What a coincidence  :Smile: 

I haven't found a solution yet, though... But if I find it, I will report here.

----------

## Nargule

I wanted my laptop console buttons to adjust the volume too, and in searching the forum I came up with a simple solutiion.

1) I emerged hotkeys

2) Using xev, I figured out the keycodes (note, the keycodes I got from showkey were different, the xev codes are the ones that worked for me)

3) Following the hotkeys man, I created a new device and called the file presarioX1000.def:

```
<definition>

  <config model="Compaq Presario X1000">

     <VolUp keycode="176"/>

     <VolDown keycode="174"/>

     <Mute keycode="160"/>

   </config>

   <contributor>

      <name>Tom Corwine</name>

      <email>hotkeys@corwine.org</email>

   </contributor>

</definition>
```

4) I modified the hotkeys.conf:

```
############################################################

# Global configuration for hotkeys                         #

############################################################

# These are the default values.

# A line starting with # is a comment.

### Specify the default keyboard  (without the .def extension) so you

### don't need to specify -t every time

Kbd=presarioX1000

# CDROM=/dev/cdrom

# Audio stuff added by Tom Corwine

VolUp=amixer set Master 2+

VolDown=amixer set Master 2-

Mute=amixer set Master toggle

# End stuff added by Tom Corwine

# PrevTrack=xmms --rew

# Play=xmms --play-pause

# Stop=xmms --stop

# Pause=xmms --pause

# NextTrack=xmms --fwd

# Rewind=

# WebBrowser=mozilla

# Email=mozilla -mail

# Calculator=xcalc

# FileManager=gmc

# MyComputer=gmc

# MyDocuments=gmc

# Favorites=gnome-moz-remote --remote=openBookmarks

# Transfer=gtp

# Record=grecord

# Shell=xterm -rv

# ScreenSaver=xscreensaver-command -activate

# NewsReader=mozilla -news

# Communities=mozilla -remote 'openURL(http://slashdot.org)'

# Search=mozilla -remote 'openURL(http://google.com)'

# Idea=mozilla -remote 'openURL(http://sourceforge.net)'

# Shopping=mozilla -remote 'openURL(http://thinkgeek.com)'

# Go=mozilla -remote 'openURL(http://linux.com)'

# Print=lpr

# Rotate=

# osd_font=-arphic-ar pl kaitim big5-bold-i-normal--0-250-0-0-c-0-*-*

### For the color, you can either use the strings in /etc/X11/rgb.txt,

### or use the RGB syntax #RRGGBB, e.g. ##A086FF

# osd_color=LawnGreen

# osd_timeout=3

### osd_position is either 'top' or 'bottom'

# osd_position=bottom

# osd_offset=25
```

5) Then I modified my .xintrc to start hotkeys -Z when X starts. The -Z switch surpresses the splash screen.

Hope this helps someone. Now all I have to do is figure out how to get the "mute" LED to light up.

----------

## elestedt

 *Nargule wrote:*   

> Hope this helps someone. Now all I have to do is figure out how to get the "mute" LED to light up.

 

If your alsamixer shows a external emplifier - try toggling it to see if it lights up, it does for me (HP nw8240).

----------

