[RFC] Remapping volume buttons

MatanZ

Senior Member
Jan 13, 2012
54
27
0
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.
 

geonahta

Senior Member
May 8, 2008
175
31
0
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
0
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,339
504
183
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
0
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
0
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
 

Techvir

Senior Member
Jul 13, 2007
3,515
886
0
What i have done as a temporary measure is edit the
/system/usr/keylayout/sec_key.kl

so that i can use volume down button to start camera as well as take pics

 
  • Like
Reactions: musashiro

wonghyf

Senior Member
Sep 18, 2006
126
17
38
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

Techvir

Senior Member
Jul 13, 2007
3,515
886
0
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
126
17
38
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
0
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,339
504
183
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
0
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.