[RFC] Remapping volume buttons

Search This thread

MatanZ

Senior Member
Jan 13, 2012
54
27
my.svgalib.org
The volume buttons can be remapped to other buttons by editing the file /system/usr/keylayout/sec_key.kl. The problem is changing this file requires a reboot to take affect.

I wrote a daemon to allow on the fly remapping. It works by using uinput subsystem to create a virtual keyboard, listening to the real keyboard /dev/input/event1, and sending the mapped keys to the virutal keyboard whenever a key is pressed.

In order to use it, you need to edit the file /system/usr/keylayout/sec_key.kl, removing (or commenting out with #) the first two lines, and reboot. After this step, the volume buttons are ignored. Now run the daemon (as root). The default configuration is to send SPACE/SHIFT+SPACE for VOL-/+ to firefox and the default browser, down/up arrow to tapatalk, and VOL-/+ to everything else.

The daemon opens a named pipe on /app-cache/.uinput-virtual-keyboard-fifo and can be configured using this pipe.

For example, the command
echo profile com.sec.android.app.ve 231 44
Will map the keys in the video editor to CALL (open phone) and Z.

The daemon is at http://my.svgalib.org/android/pgdn

Source at http://my.svgalib.org/android/pgdn.c

Comments are welcome.
 

two_handed

Senior Member
Dec 13, 2011
279
83
You, dear sir, are a genious.

Really appreciate your effort. Works like a charm.

Sent from my GT-N7000 using XDA App
 

geonahta

Senior Member
May 8, 2008
175
31
Can you provide for a key remap for the stock camera application? Volume up capture picture, volume down focus mode?
Thank you!

Sent from my GT-N7000 using xda premium
 

MatanZ

Senior Member
Jan 13, 2012
54
27
my.svgalib.org
The file with the meaning of the keys is /system/usr/keylayout/Vendor_04E8_Product_7021.kl according to it FOCUS is 211 and CAMERA is 212. Unfortunately, FOCUS appears to do nothing, so if you run the command

Code:
echo profile com.sec.android.app.camera 211 212 > /app-cache/.uinput-virtual-keyboard-fifo

The VOL+ button will take a picture, but the VOL- button does nothing.

(There is currently no configuration file, so this command needs to run everytime the daemon is started).
 

mac231us

Senior Member
Oct 26, 2010
2,434
519
The volume buttons can be remapped to other buttons by editing the file /system/usr/keylayout/sec_key.kl. The problem is changing this file requires a reboot to take affect.

I wrote a daemon to allow on the fly remapping. It works by using uinput subsystem to create a virtual keyboard, listening to the real keyboard /dev/input/event1, and sending the mapped keys to the virutal keyboard whenever a key is pressed.

In order to use it, you need to edit the file /system/usr/keylayout/sec_key.kl, removing (or commenting out with #) the first two lines, and reboot. After this step, the volume buttons are ignored. Now run the daemon (as root). The default configuration is to send SPACE/SHIFT+SPACE for VOL-/+ to firefox and the default browser, down/up arrow to tapatalk, and VOL-/+ to everything else.

The daemon opens a named pipe on /app-cache/.uinput-virtual-keyboard-fifo and can be configured using this pipe.

For example, the command
echo profile com.sec.android.app.ve 231 44
Will map the keys in the video editor to CALL (open phone) and Z.

The daemon is at http://my.svgalib.org/android/pgdn

Source at http://my.svgalib.org/android/pgdn.c

Comments are welcome.
Thanks for the information !..great work. Can you provide how to remap the power button for taking pictures with the camera (sorely missed especially for this device due to its size; touchscreen very awkward esp. for 1-handed shots and have been asking a lot for this even tried to do this myself based on SGS2 hacked camera but got nowhere)

Thanks !
 

MatanZ

Senior Member
Jan 13, 2012
54
27
my.svgalib.org
You can try with this (untested) daemon which allows for mapping all four hardware buttons:

http://my.svgalib.org/android/pgdn4

You need to disable the buttons by also removing the 102 and 116 lines from the file /system/usr/keylayout/sec_key.kl and rebooting. By default home and power map to home and power on all applications except for camera, where power, vol+ and vol- map to camera button (take a picture).
 
  • Like
Reactions: Techvir

schokibaerchen

Senior Member
Oct 11, 2009
113
14
Stockelsdorf
I've tried to map the volume buttons 4cm down on the left side.
Wont work. Then i tried for another 2 hours to map them to the right side of my note. (under the on/off button).
Didn't work too...
What am i doing wrong? Do i need a screwdriver to execute the script and the buttons?
:p
 

wonghyf

Senior Member
Sep 18, 2006
127
17
Could someone explain in more detail how to run a daemon? Thanks.

[Edit] Solved. I used Script manager to run it as "is executable" as root and at boot up. But I have to copy it to the internal memory to run it, otherwise, "permission denied".
 
Last edited:
  • Like
Reactions: Techvir
Thanks. really like it but few issues noted

1. For the camera mod as suggested in post 6 - The home button does not work after the daemon is run. Long press works however.

2. The daemon needs to be in internal memory for it to work with script manager. If in sd card it shows permission denied.
Also since its in internal memory, it gets deleted every time at boot and hence have to copy it there every time after boot.

Is there any other app to run the daemon from sdcard ?


Thanks
 

wonghyf

Senior Member
Sep 18, 2006
127
17
Thanks. really like it but few issues noted

1. For the camera mod as suggested in post 6 - The home button does not work after the daemon is run. Long press works however.

2. The daemon needs to be in internal memory for it to work with script manager. If in sd card it shows permission denied.
Also since its in internal memory, it gets deleted every time at boot and hence have to copy it there every time after boot.

Is there any other app to run the daemon from sdcard ?


Thanks

I put the file under /system, and it won't be deleted every time it bootup.
 
  • Like
Reactions: Techvir

MatanZ

Senior Member
Jan 13, 2012
54
27
my.svgalib.org
I put the file under /system, and it won't be deleted every time it bootup.

I think the best partition is /data. This partition is ext4, so supports executable, symlinks, etc. And is mounted rw, so it does not need to be remounted for every change.

If you want to make the daemon suid root, it has to be on /system, since /data is by default mounted with option nosuid.
 
  • Like
Reactions: Techvir

mac231us

Senior Member
Oct 26, 2010
2,434
519
You can try with this (untested) daemon which allows for mapping all four hardware buttons:

http://my.svgalib.org/android/pgdn4

You need to disable the buttons by also removing the 102 and 116 lines from the file /system/usr/keylayout/sec_key.kl and rebooting. By default home and power map to home and power on all applications except for camera, where power, vol+ and vol- map to camera button (take a picture).

Thanks ! works like a charm ! (finally camera with power button to take picture on note..so many camera mods but no one doing this mod which was so easily available on sgs, sgs2), Thanks !
 

beginner

Senior Member
Nov 18, 2005
790
9
should be possible to input the passw with the volume control?

my email forces me to lock with strong password. Should be possible to start and script with a remapped button, producing to input the password stored on it and unlock screen?

Thanks a lot.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 8
    The volume buttons can be remapped to other buttons by editing the file /system/usr/keylayout/sec_key.kl. The problem is changing this file requires a reboot to take affect.

    I wrote a daemon to allow on the fly remapping. It works by using uinput subsystem to create a virtual keyboard, listening to the real keyboard /dev/input/event1, and sending the mapped keys to the virutal keyboard whenever a key is pressed.

    In order to use it, you need to edit the file /system/usr/keylayout/sec_key.kl, removing (or commenting out with #) the first two lines, and reboot. After this step, the volume buttons are ignored. Now run the daemon (as root). The default configuration is to send SPACE/SHIFT+SPACE for VOL-/+ to firefox and the default browser, down/up arrow to tapatalk, and VOL-/+ to everything else.

    The daemon opens a named pipe on /app-cache/.uinput-virtual-keyboard-fifo and can be configured using this pipe.

    For example, the command
    echo profile com.sec.android.app.ve 231 44
    Will map the keys in the video editor to CALL (open phone) and Z.

    The daemon is at http://my.svgalib.org/android/pgdn

    Source at http://my.svgalib.org/android/pgdn.c

    Comments are welcome.
    3
    The latest version has a configuration file: /sdcard/.pgdn .


    With configuration file http://my.svgalib.org/android/config.pgdn and with /system/usr/keylayout/sec_key.kl containing:

    key 115 VOLUME_UP WAKE
    #key 114 VOLUME_DOWN WAKE
    #key 102 HOME WAKE
    key 107 ENDCALL
    key 105 DPAD_LEFT
    key 106 DPAD_RIGHT
    key 103 DPAD_UP
    key 108 DPAD_DOWN
    key 232 DPAD_CENTER
    #key 116 POWER WAKE
    key 212 CAMERA WAKE

    The power key works as shutter key in camera application and as the usual power key when not in camera application.
    2
    The file with the meaning of the keys is /system/usr/keylayout/Vendor_04E8_Product_7021.kl according to it FOCUS is 211 and CAMERA is 212. Unfortunately, FOCUS appears to do nothing, so if you run the command

    Code:
    echo profile com.sec.android.app.camera 211 212 > /app-cache/.uinput-virtual-keyboard-fifo

    The VOL+ button will take a picture, but the VOL- button does nothing.

    (There is currently no configuration file, so this command needs to run everytime the daemon is started).
    1
    You can try with this (untested) daemon which allows for mapping all four hardware buttons:

    http://my.svgalib.org/android/pgdn4

    You need to disable the buttons by also removing the 102 and 116 lines from the file /system/usr/keylayout/sec_key.kl and rebooting. By default home and power map to home and power on all applications except for camera, where power, vol+ and vol- map to camera button (take a picture).
    1
    how exactly do we run it... do i go to the file in root explorer and cliclk on the file or do something else...
    i have the pgdn4 placed in /data

    If you are aware of the Linux way of "services" you can add a file to /system/etc/init.d/

    if not, then you can do something like (adb or terminal):

    # mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
    # echo "/data/pgdn" >> /system/etc/init.d/99complete
    # reboot

    If you did not understand what is happening here then DO NOT DO IT. The reboot will help in two things, making your /system read only once again and making sure it worked, I had to spend one hour with a phone with a disabled power and home key while not in front of a computer to fix it. So I can tell you its pretty bad to lose any way of waking your phone ;)