Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[RFC] Remapping volume buttons

OP MatanZ

4th February 2012, 01:39 PM   |  #1  
OP Member
Thanks Meter: 25
 
46 posts
Join Date:Joined: Jan 2012
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.
The Following 8 Users Say Thank You to MatanZ For This Useful Post: [ View ]
4th February 2012, 01:51 PM   |  #2  
Senior Member
Thanks Meter: 50
 
176 posts
Join Date:Joined: Dec 2011
You, dear sir, are a genious.

Really appreciate your effort. Works like a charm.

Sent from my GT-N7000 using XDA App
4th February 2012, 04:26 PM   |  #3  
Senior Member
Thanks Meter: 29
 
171 posts
Join Date:Joined: May 2008
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
4th February 2012, 05:02 PM   |  #4  
OP Member
Thanks Meter: 25
 
46 posts
Join Date:Joined: Jan 2012
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).
The Following 2 Users Say Thank You to MatanZ For This Useful Post: [ View ]
4th February 2012, 11:02 PM   |  #5  
Senior Member
Thanks Meter: 209
 
1,058 posts
Join Date:Joined: Oct 2010
Quote:
Originally Posted by MatanZ

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 !
4th February 2012, 11:38 PM   |  #6  
OP Member
Thanks Meter: 25
 
46 posts
Join Date:Joined: Jan 2012
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).
The Following User Says Thank You to MatanZ For This Useful Post: [ View ]
4th February 2012, 11:46 PM   |  #7  
schokibaerchen's Avatar
Senior Member
Flag Stockelsdorf
Thanks Meter: 14
 
113 posts
Join Date:Joined: Oct 2009
More
Wink
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
5th February 2012, 04:02 AM   |  #8  
Senior Member
Thanks Meter: 477
 
2,304 posts
Join Date:Joined: Jul 2007
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

The Following User Says Thank You to drgopoos For This Useful Post: [ View ]
5th February 2012, 07:55 AM   |  #9  
Member
Thanks Meter: 9
 
85 posts
Join Date:Joined: Sep 2006
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 by wonghyf; 5th February 2012 at 08:37 AM.
The Following User Says Thank You to wonghyf For This Useful Post: [ View ]
5th February 2012, 04:28 PM   |  #10  
Senior Member
Thanks Meter: 477
 
2,304 posts
Join Date:Joined: Jul 2007
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

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes