New additions to KeyCode on android4.4

Source: Internet
Author: User

KeyCode is a well-defined Android, but sometimes it is not enough to meet the needs, customization will inevitably involve a new increase in keycode. Divided into two parts, the drive and the framework, where the framework section is mainly explained:

first, the driving part:

1. Defined in the following documents

such as Key_sms

#defineKEY_SMS 252

Files that may be involved (may also need to be in another file):

kernel\include\linux\input.h

Bionic\libc\kernel\common\linux\input.h

External\kernel-headers\original\linux\input.h

External\qemu\linux_keycodes.h


2. Add keypad layout file keyboard mapping,Linux and androidkey Mappings

Such as:

Key 252 SMS

Note The KL file used for the version and the project, and the KL used in the ADB shell to enter system/usr/keylyout/can be modified to confirm the use of KL

The new key that is generally defined in KPD.C uses ***-KPD.KL, which means that the registered input device is ***-KPD ***-KPD.KL

GENERIC.KL and QWERTY.KL are generally used when adding new device names

GENERIC.KL and QWERTY.KL in alps/frameworks/base/data/keyboards/

-KPD.KL in config/<projectname>/

Where 252 is the Linux key code, SMS is the android recognition key value if it is necessary to wake up the system and also need to add wake


Ii. Framework Section

1. Modify Java recognition KeyCode

Framework/native/include/input/keycodelabels.h

Keycodes data structures are added later

{"SMS", 220}

Framework/native/include/android/keycodes.h

Add akeycode_sms = 220 in the key definition item;

2. modifying Java keyboard events

Framework/base/core/java/android/view/keyevent.java

/**

* @hide

*/

public static final int keycode_sms = 220;

The last button is the new

private static final int last_keycode==keycode_sms;

The above/**/comment Code is the Android non-open API or variable definition, need to add the identification of Java doc, otherwise run make Update-api to build through


Increased name.append (keycode_sms, "keycode_sms") in Keycode_symbolic_names;

If it is the system key, modify the Framework/base/libs/ui/input.cpp

Issystemkey () Add case akeycode_sms:

3. Modify the XML file descriptor Framework/base/core/res/res/values/attr.xml

<enum name= "keycode_sms" value= "/>"

4. Add test verification Log on Android

Framework\base\policy\src\com\android\internal\polidy\impl\phonewindowmanager.java

Increased in interceptkeybeforedispatching ()

if (keycode== keyevent.keycode_sms) {

LOG.D (TAG, "Interceptkeyti keycode_sms keycode=" + keycode + "down=" + Down + "repeatcount=" + repeatcount + "Ke Yguardon= "+ Keyguardon +" mhomepressed= "+ mhomepressed +" cancled= "+ canceled)


P.S. Not all Linux KeyCode frameworks will support processing, and if you need to add a lot of keystrokes, you may be over 256 (e.g. Touch panel gesture recognition will use a key)

Inputreader.cpp's Keyboardinputmapper This class's process function will first determine if it is iskeyboardorgamepadkey.This will determine the size of the key, the condition is: 1. Less than 2722. Greater than 3523. Greater than or equal to 256 and less than 2724. is greater than or equal to 288 and less than 320 satisfies one. Otherwise it will intercept, not go to Inputdispatcher and Phonewindowmanager.java.

Follow the steps above to modify your code to add a new keycode to your Android system.


New additions to KeyCode on android4.4

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.