You are not logged in.

#1 2014-01-17 03:26:16

EscapedNull
Member
Registered: 2013-12-04
Posts: 129

Sony media keys not working

Has anyone been able to make the Sony media keys work on Arch? They show up as a keyboard under Gnome's "System Information" GUI, but I wasn't able to locate them on lsusb/lspci/lshw. I tried installing xf86-input-keyboard and they still don't work. It would be convienent to have the volume keys working so I don't have to open alsamixer just to change the volume. Brightness would be nice too. Oddly, the Hibernate key works fine out of the box and it is an "fn" key like the rest. Any insight is appreciated.

Offline

#2 2014-01-19 19:28:15

EscapedNull
Member
Registered: 2013-12-04
Posts: 129

Re: Sony media keys not working

If it makes any difference, here is the output of some scankey commands:

showkey -s
kb mode was UNICODE
[ if you are trying this under X, it might not work
since the X server is also reading /dev/console ]

press any key (program terminates 10s after last keypress)...
0x9c
0x74 0xf4
0xe0 0x20 0xe0 0xa0
0xe0 0x2e 0xe0 0xae
0xe0 0x30 0xe0 0xb0
0xe0 0x4c 0xe0 0xcc
0xe0 0x54 0xe0 0xd4
0xe0 0x56 0xe0 0xd6

showkey -a
Press any keys - Ctrl-D will terminate this program

      0 0000 0x00
     27 0033 0x1b
     91 0133 0x5b
     50 0062 0x32
     53 0065 0x35
    126 0176 0x7e
     27 0033 0x1b
     91 0133 0x5b
     50 0062 0x32
     54 0066 0x36
    126 0176 0x7e
      0 0000 0x00
      0 0000 0x00
      0 0000 0x00
      4 0004 0x04

showkey -k
kb mode was UNICODE
[ if you are trying this under X, it might not work
since the X server is also reading /dev/console ]

press any key (program terminates 10s after last keypress)...
keycode  28 release
keycode 191 press
keycode 191 release
keycode 113 press
keycode 113 release
keycode 114 press
keycode 114 release
keycode 115 press
keycode 115 release
keycode 224 press
keycode 224 release
keycode 225 press
keycode 225 release
keycode 227 press
keycode 227 release

In order from first to last: toggle touchpad, toggle mute, volume down, volume up, brightness down, brightness up, LCD/VGA.

Offline

#3 2014-01-19 19:58:29

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,803

Re: Sony media keys not working

Where to start?
What do you mean by making them work on Arch?  It looks like the keys work, just just have to give them meaning and purpose.
You mentioned Gnome, Is that the environment you are using?  Or are you using some other environment, such as Openbox or i3 as well?

Fire up the program xev.  That program will show you X events and will let you see if the keys are mapped in X, and what they are called.
After that, we can talk about binding those keys.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#4 2014-01-19 22:07:11

EscapedNull
Member
Registered: 2013-12-04
Posts: 129

Re: Sony media keys not working

ewaller wrote:

Where to start?
What do you mean by making them work on Arch?  It looks like the keys work, just just have to give them meaning and purpose.
You mentioned Gnome, Is that the environment you are using?  Or are you using some other environment, such as Openbox or i3 as well?

Fire up the program xev.  That program will show you X events and will let you see if the keys are mapped in X, and what they are called.
After that, we can talk about binding those keys.

Sorry, I should have been more specific. I just came across the wiki page on special keys and thought the showkey output might help. I'm still kind of new to X configuration. If I recall correctly, the keys did work under Gnome. I'm now using i3 as my window manager. I can see the KeyPress events in xev. Could you please point me in the right direction of assigning a command to KeyPress event? I think I can use the amixer command to change the volume, I just need to figure out how to bind the correct key to it.

Offline

#5 2014-01-19 22:45:26

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,803

Re: Sony media keys not working

For i3, you need to edit your ~/.i3/config file to bind keys to functions of your choosing:

Here is mine for i3 on an HP Pavilion DV4

# This file has been auto-generated by i3-config-wizard(1).
# It will not be overwritten, so edit it as you like.
#
# Should you change your keyboard layout somewhen, delete
# this file and re-run i3-config-wizard(1).
#

# i3 config file (v4)
#
#Please see http://i3wm.org/docs/userguide.html for a complete reference!

set $mod Mod4

# Font for window titles. Will also be used by the bar unless a different font
# is used in the bar {} block below. ISO 10646 = Unicode
#font -*-charter-medium-r-*-*-*-100-*-*-*-*-*-*
# The font above is very space-efficient, that is, it looks good, sharp and
# clear in small sizes. However, if you need a lot of unicode glyphs or
# right-to-left text rendering, you should instead use pango for rendering and
# chose a FreeType font, such as:
font pango:DejaVu Sans 8


# Use Mouse+$mod to drag floating windows to their wanted position
floating_modifier $mod

# start a terminal
bindsym $mod+Return exec i3-sensible-terminal

# kill focused window
bindsym $mod+q kill

# start dmenu (a program launcher)
bindsym $mod+d exec dmenu_run
# There also is the (new) i3-dmenu-desktop which only displays applications
# shipping a .desktop file. It is a wrapper around dmenu, so you need that
# installed.
# bindsym $mod+d exec --no-startup-id i3-dmenu-desktop

# change focus
bindsym $mod+j focus left
bindsym $mod+k focus down
bindsym $mod+l focus up
bindsym $mod+semicolon focus right

# alternatively, you can use the cursor keys:
bindsym $mod+Left workspace prev
bindsym $mod+Down workspace focus down
bindsym $mod+Up focus up
bindsym $mod+Right workspace next

# move focused window
bindsym $mod+Shift+j move left
bindsym $mod+Shift+k move down
bindsym $mod+Shift+l move up
bindsym $mod+Shift+semicolon move right

# alternatively, you can use the cursor keys:
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right

# split in horizontal orientation
bindsym $mod+h split h

# split in vertical orientation
bindsym $mod+v split v

# enter fullscreen mode for the focused container
bindsym $mod+f fullscreen

# change container layout (stacked, tabbed, toggle split)
bindsym $mod+s layout stacking
bindsym $mod+w layout tabbed
bindsym $mod+e layout toggle split

# toggle tiling / floating
bindsym $mod+space floating toggle

# change focus between tiling / floating windows
bindsym $mod+Shift+space focus mode_toggle

# focus the parent container
bindsym $mod+a focus parent

# focus the child container
#bindsym $mod+d focus child

# switch to workspace
bindsym $mod+1 workspace 1
bindsym $mod+2 workspace 2
bindsym $mod+3 workspace 3
bindsym $mod+4 workspace 4
bindsym $mod+5 workspace 5
bindsym $mod+6 workspace 6
bindsym $mod+7 workspace 7
bindsym $mod+8 workspace 8
bindsym $mod+9 workspace 9
bindsym $mod+0 workspace 10

# move focused container to workspace
bindsym $mod+Shift+1 move container to workspace 1
bindsym $mod+Shift+2 move container to workspace 2
bindsym $mod+Shift+3 move container to workspace 3
bindsym $mod+Shift+4 move container to workspace 4
bindsym $mod+Shift+5 move container to workspace 5
bindsym $mod+Shift+6 move container to workspace 6
bindsym $mod+Shift+7 move container to workspace 7
bindsym $mod+Shift+8 move container to workspace 8
bindsym $mod+Shift+9 move container to workspace 9
bindsym $mod+Shift+0 move container to workspace 10

# reload the configuration file
bindsym $mod+Shift+c reload
# restart i3 inplace (preserves your layout/session, can be used to upgrade i3)
bindsym $mod+Shift+r restart
# exit i3 (logs you out of your X session)
bindsym $mod+Shift+e exit

#bindsym $mod+Shift+e exec "i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -b 'Yes, exit i3' 'i3-msg exit'"

# resize window (you can also use the mouse for that)
mode "resize" {
        # These bindings trigger as soon as you enter the resize mode

        # Pressing left will shrink the windowâs width.
        # Pressing right will grow the windowâs width.
        # Pressing up will shrink the windowâs height.
        # Pressing down will grow the windowâs height.
        bindsym j resize shrink width 10 px or 10 ppt
        bindsym k resize grow height 10 px or 10 ppt
        bindsym l resize shrink height 10 px or 10 ppt
        bindsym semicolon resize grow width 10 px or 10 ppt

        # same bindings, but for the arrow keys
        bindsym Left resize shrink width 10 px or 10 ppt
        bindsym Down resize grow height 10 px or 10 ppt
        bindsym Up resize shrink height 10 px or 10 ppt
        bindsym Right resize grow width 10 px or 10 ppt

        # back to normal: Enter or Escape
        bindsym Return mode "default"
        bindsym Escape mode "default"

}

bindsym $mod+r mode "resize"


# Bindings for my HP Pavilion 

bindsym XF86AudioPlay exec mpc toggle
bindsym XF86AudioPrev exec mpc prev
bindsym XF86AudioNext exec mpc next
bindsym XF86AudioStop exec mpc stop
bindsym XF86AudioRaiseVolume exec pavolume increase
bindsym XF86AudioLowerVolume exec pavolume decrease
bindsym XF86AudioMute exec pavolume mute
bindsym XF86Save exec dmenu_run
bindsym $mod+Shift+x exec x48
bindsym $mod+Tab workspace next
bindsym $mod+Shift+Tab workspace prev
#bindsym Mod1+Tab workspace next
bindsym $mod+Menu exec i3-winmenu.py

bindsym $mod+XF86Save exec gmrun
for_window [title="Execute program feat. completion"] floating enable' border none; focus mode_toggle
for_window [title="x48-0.6.4"] floating enable' border none; focus mode_toggle
for_window [title="Wicd Network Manager"] floating enable' border none; focus mode_toggle

# Float notifications

for_window [class="Xfce4-notifyd"] floating enable; border none; focus mode_toggle

# Start i3bar to display a workspace bar (plus the system information i3status
# finds out, if available)
bar {
        status_command i3status
}

#exec --no-startup-id i3-msg 'workspace 2; exec firefox; workspace 1'
exec --no-startup-id i3-msg 'workspace 10; exec claws-mail; workspace 1'
exec --no-startup-id exec nitrogen --restore
exec --no-startup-id exec compton
#exec --no-startup-id exec xcompmgr
#exec --no-startup-id exec cairo-compmgr
exec --no-startup-id exec conky
exec --no-startup-id exec mpd
exec --no-startup-id emacs
exec --no-startup-id exec wicd-gtk -t

Pay close attention to the bindkey lines, like this:
bindsym XF86AudioPlay exec mpc toggle 
That key starts and stops mpd audio playback using the mpc frontend.
You will use the key names that xev tells you

Be sure to read https://wiki.archlinux.org/index.php/i3

Edit: you mentioned volume.  Note that my config uses a script called pavolume.  I wrote that smile
Here it is:

#!/bin/bash
oldvolume=$(pacmd dump|grep set-sink-volume|grep alsa |cut -f3 -d' ')
pacmd dump | grep set-sink-mute | grep alsa | grep yes > /dev/null
oldmute=$?
case $1 in

increase)
    newvolume=$(($oldvolume + 0x400))
    if (($newvolume >0x10000)) ; then
        newvolume=$((0x10000))
    fi
    pacmd set-sink-volume alsa_output.pci-0000_00_1b.0.analog-stereo $(printf '0x%x' $((newvolume)) ) 
    ;;

decrease)
    newvolume=$(($oldvolume - 0x400))
    if (($newvolume < 0 )) ; then
        newvolume=$((0x0000))
    fi
    pacmd set-sink-volume alsa_output.pci-0000_00_1b.0.analog-stereo $(printf '0x%x' $((newvolume)) ) 
    ;;

mute)
    if [[(($oldmute == 0))]] ; then
       pacmd set-sink-mute alsa_output.pci-0000_00_1b.0.analog-stereo 0
    else
       pacmd set-sink-mute alsa_output.pci-0000_00_1b.0.analog-stereo 1
    fi
    ;;
*)
    echo "usage pavolume increase | decrease | mute"
esac

I use pulse audio.  If you use this script, put it someplace where it will be found by your path, and make it executable by you

Last edited by ewaller (2014-01-19 22:49:21)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#6 2014-01-20 00:09:12

EscapedNull
Member
Registered: 2013-12-04
Posts: 129

Re: Sony media keys not working

I'm just using alsa (haven't felt the need to install pulseaudio), so here's what I ended up with:

bindsym XF86AudioLowerVolume exec amixer -q set Master 5-
bindsym XF86AudioRaiseVolume exec amixer -q set Master 5+
bindsym XF86AudioMute exec $(amixer get Master | grep off > /dev/null && amixer -q set Master unmute) || amixer -q set Master mute

I didn't even have to edit any X configuration files using this method, which I was happy about. I'm still working on brightness, but that's another issue. Thanks so much ewaller! This is exactly what I wanted.

Edit: Apparently this was already on the wiki.

Last edited by EscapedNull (2014-01-20 00:31:20)

Offline

#7 2014-04-30 16:38:54

A_Distortion
Member
From: France
Registered: 2014-04-30
Posts: 2
Website

Re: Sony media keys not working

Exactly what i needed smile


When you have eliminated the impossible, whatever remains, however improbable, must be the truth

Offline

Board footer

Powered by FluxBB