Announcement

Collapse
No announcement yet.

[ Tutorial ] Redefine any keys of your Android Keybord, Remote Controller, Gamepad to your needs.

Collapse
This is a sticky topic.
X
X
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Originally posted by cOOLio View Post
    First of all you can redefine the key of every input device attached and recognized by your Android device. Such input devices like a IR Remote, Bluetooth Keybord and any USB HID (wireless or cable). This means every Keyboard, Remote Controller, Mouse or Gamepad can be modified to your own needs:

    What do you need:
    • Root access to your device
    • Root Explorer (I use ES FIle Explorer)
    • Text Editor (I use the build in editor of ES File Explorer)
    • Terminal
    You can also edit/create your *.kl file on your computer


    Helpfull android tools


    Easy MOD (.kl files)


    General Infos about Android key layout files (.kl)

    Key layout files are located by USB vendor, product (and optionally version) id or by input device name. The following paths are consulted in order:
    • /system/usr/keylayout/Vendor_XXXX_Product_XXXX_Version_XXXX.kl
    • /system/usr/keylayout/Vendor_XXXX_Product_XXXX.kl
    • /system/usr/keylayout/DEVICE_NAME.kl
    • /data/system/devices/keylayout/Vendor_XXXX_Product_XXXX_Version_XXXX.kl
    • /data/system/devices/keylayout/Vendor_XXXX_Product_XXXX.kl
    • /data/system/devices/keylayout/DEVICE_NAME.kl
    • /system/usr/keylayout/Generic.kl
    • /data/system/devices/keylayout/Generic.kl

    When constructing a file path that contains the device name, all characters in the device name other than '0'-'9', 'a'-'z', 'A'-'Z', '-' or '_' are replaced by '_'.

    Source: https://source.android.com/devices/input/key-layout-files.html


    Note: Do not forget to chmod 660 your own created xyz.kl files. Or use ES File Explorer to do so: Mark file (long press) >> More >> Properties >> Permissons [Change] to rw- r- r- = (Read: Owner, Group, Other | Write: Owner)






    List all connected input devices

    Use the following command at a Terminal Emulator or via the Android Debug Bridge (ADB), to find your keyboard in the list and to get the Vendor ID, Product ID, Version ID or Device Name.

    Code:
    cat /proc/bus/input/devices
    A good Android Terminal tool with large font size (to read on a TV screen)
    https://play.google.com/store/apps/d...rminalemulator


    Tipp: You can use also Gamepad tester to do so. Just press the key on the remote you want to mod and it will show you all the needed informations about the Vendor ID, Product ID, Version ID or Device Name at the bottom of the screen.





    Overview of all Android Key Codes

    At the following link you will find a overview of all possible Android key codes, that can be mapped to any ScanCode of your remote control, keybord or game controller in your key layout file.

    Note: When using a the key codes you don't have to use the beginning
    KEYCODE_ at your key layout file.

    Example:
    Code:
    KEYCODE_APP_SWITCH = APP_SWITCH


    List of all key codes >> http://developer.android.com/reference/android/view/KeyEvent.html





    Test your Keys and find the ScanCode

    To check the already set ScanCode of any key, you can use Multilanguage Keymap Redefiner (MKR) or
    Gamepad tester. (see pictures for more details)

    With Gamepad tester you can also create your device own *.kl dummy file for any keyboard or remote controller, straight saved to the right folder. And for sure, this file must be enhanced manually to your needs. But for a Gamepad it can create already the final *.kl file for your Gamepad, so you do not need any other tool (steps)


    MKR Click image for larger version Name:	Screenshot_2017-04-02-15-57-51.png Views:	1 Size:	24.7 KB ID:	639434
    Click image for larger version Name:	Screenshot_2017-04-02-15-58-00.png Views:	1 Size:	57.3 KB ID:	639435
    Click image for larger version Name:	Screenshot_2017-04-02-15-58-45.png Views:	1 Size:	57.2 KB ID:	639436










    Gamepad tester Click image for larger version Name:	Screenshot_2017-04-02-15-54-24.png Views:	1 Size:	62.3 KB ID:	639437
    Click image for larger version Name:	Screenshot_2017-04-02-15-55-10.png Views:	1 Size:	34.4 KB ID:	639438






    Enhanced MOD (remote.conf)

    With the following described enhanced modifications you can easily add any IR Remote Controler to also work with your android device. It helps you also in case some keys of your IR Remote aren't working (not set).

    Note: A full description on how to generate your own remote.conf file for any other IR Remote Controler can be found already >> here <<

    The remote.conf file to modify can be found her: system/etc/remote.conf
    Right now we will check only how to add the non working (not set) keys to our needs.

    First we have to check if debug is enabled in your remote.conf file. Because without this setting we will see nothing whats going on/wrong.

    Code:
    debug_enable = 1
    If it is set to 0, change it to 1 and reboot your device.

    Now open a Terminal session and enter the following commands
    Code:
    su
    to get root access

    Code:
    dmesg -c
    to clean all debug messages


    Now click that key on your remote control that does not even work when testing it with MKR or Gamepad tester

    Code:
    dmesg|grep "code is 0x"
    To see only those messages on keys who are not set to our remote.conf file


    You will see right now a masse like this: Wrong custom code is 0xaabbcccc

    So our needed ScanCode to set at remote.conf is: bb

    Now we can set the right ScanCode to our remote.conf and *.kl files like this.


    remote.conf
    Code:
    0xbb 123

    Vendor_XXXX_Product_XXXX.kl
    Code:
    key 123 DPAD_UP

    So 0xbb is the key we press on our remote and 123 is the ScanCode to this key and it is set to in our *.kl file as DPAD_UP



    Tipps & Tricks

    While your are generating your own configurations file I should finally also mention the follwing tipps & tricks I made.

    Android Key Layout files (*.kl)

    The one file who fits them all (Generic.kl)

    There are always already a lot of Key Layout files included to you Android. The most important is the Generic.kl file. Because this file is always used in case there is no other specific file, created only to mach to one specific device. So in case there is no kl file that match to your device Vendor & Device ID or device name, Android will always use the Generic.kl file. So it is not a good idea to change anything to the Generic.kl. Because this could mess up the function of other input devices, that have also no own *.kl file. So it is always better to create a specific key file for each individual input device.

    Error solving while creating your own *kl file
    Sometimes while creating your own key layout files, things do not work as they should. In those cases it is good to now what causes the issue.
    One of my best practice to check if the issue comes from your own created file or not, is to move all already existing *.kl to a sub folder. So the system has only the one file you created. But keep in mind that now no other input device will work anymore until you copy them back to it original folder. And you should always have a mouse attached to your Android device. Becasue this will be the only device that works without any *.kl file.

    Summary: Use a Mouse as input backup & remove all other *.kl files temporary.



    General tipps while editing

    Keep always a copy of the original configurations file as reference, by just renaming the original file like this:
    • remote.conf >> remote.conf_
    • Generic.kl >> Generic.kl_
    Thanks for your amazing tutorial.
    May I have a question? My remote control partially works. Some unworked keys show wrong custom code is 0xaabb4040, so I changed the factory_code to 0x40400001. The unworked keys are now working, but the original working ones are now out of work. They show different wrong custom code as 0xaabbef10, so the factory_code is different. Can I solve this problem? Can edit two types of factory_code in one set of remote.conf? Thanks for your help.

    Comment


      #17

      X96 Max Android TV box

      i read the tutorial Above
      But it seem the link is broken in the Enhanced MOD (remote.conf) section where is says "A full description on how to generate your own remote.conf file..."
      I need some help to understand the correct way to add keys to the IR remote config files.
      I have a programmable RCA Media-center remote. I have programed it to control Kodi, WMC, Plex all using one device setup it works great on my windows PC.
      I now added my android TV box X96max to a different device button and programed all the keys from the remote that came with the TV box. But find that remote lacks many keys like stop, jump back/forward, page up/down to name a few i would like to add these buttons/keys to the remote config files of Android. I know i could edit the keymap in kodi but i would like to just do it once and have it work for most apps that could use the extra buttons.

      On this box there is no remote.conf file in system/etc
      but i do have remote.cfg remote.tab1 remote.tab2 remote.tab3 in the system/vendor/etc

      So am i to edit remote.tab2 or create and add a remote.conf

      I notice in the remote.tab2 file they assign hex value to a android key command it looks like. but it is not clear how you come up with the hex value for new keys the original remote don't have or if i can pick any unused hex value and assign it.
      Since i am added buttons/keys that are new and i can assign any hex value to the button i want when i setup my Media center IR remote it seems i just pick a hex value.
      I see that the IR remote buttons they have setup in remote.tab2 mostly match the key command numbers from the Generic.kl file and they assigned a hex value to it but notice the hex value jumps around and is not in sequence.

      Code:
       remote.tab2        
      0x41 113  #MUTE        
      0x18 115  #VOLUMEUP        
      0x10 114  #VOLUMEDOWN  
      
      Generic.kl
      key 113   VOLUME_MUTE
      key 114   VOLUME_DOWN
      key 115   VOLUME_UP

      So if i could get some guidance that would be great maybe i could do it right the first time and not keep guessing,
      Thanks

      I asked this question in the S905X2 forum section here but seems it got a lot of views but no reply's so i though it would be better to post it here where it might get eyes that know the topic.
      If this is considered against the rules or double posting then please remove the the post in one of the places.
      Last edited by Rainey; 07-27-2019, 20:00.

      Comment

      Working...
      X