Android Add (Keyboard) button

Source: Internet
Author: User

To add camera keys as an example (red is what you need to add)

First, Kernel key value Definition

( 1 ) key Scan code

Scancode is an integer type defined by the input driver framework of Linux and can refer to the Input.h header file, which is the key value getevent gets.

#define KEY_Q 16

#define KEY_W 17

#define KEY_E 18

#define KEY_R 19

#define KEY_T 20

#define Key_camera 199

( 2 ) keyboard layout file (*.KL)

Converts the input event's key value into a keyboard-specific key for use by the Android upper layer, when it is completed by the keyboard layout file (*.KL). Put it under the/system/usr/keylayout/.

The QWERT.KL is defined as follows:

Scancode + String Value

Key Q

Key + W

Key E

Key R

Key T

Where Scancode is the value of the driver report (that is, the key value defined in the driver input.h)

A : Add KL File:

abcxxxx. KL (filename must be the same as the name of the device device for input)

Key 199 CAMERA

"199 for driver-defined scancode,CAMERA for Android keycodes[] defines the Keylabel character corresponding to the key"

Note:

1 ) KL The file must be entered with the keyboard input Devic The name of the is the same, otherwise Eventhub cannot find the corresponding when loading the device KL Loading the default QWERT.KL, causing key-value conversion errors

2 ) KL in the Scancode and the Android The keylabel characters defined in the. s must correspond, otherwise the error will be converted. keymapper When converting is based on scancode, to determine the corresponding key character, and then according to this character in the keycodes to determine the key values in the corresponding Android .

B : KL file is added to system

Place KL files (usually) in/device/qcom/xxx/(XXX is the project name)

( 1 ) androidboard.mk Add:

Include $ (clera_vars)

local_module: = abcxxxx.kl

Local_module_targs: = Optional eng

Local_module_class: = ETC

Local_src_files: = $ (Local_module)

Local_module_path: = $ (target_out_keylayout)

Include $ (build_prebuilt)

(2)/device/qcom/common/base.mk Add

KEYPAD + = ABCXXXX.KL

Note: The KL file will not be packaged into the/system/usr/keylayout/if not added

Second, Android Add keys in

( 1 ) to define the key corresponding to the Key Label

At the end of the keycodes[] array, add the key label

That

static const Keycodelabel keycodes[] = {

...

Define_keycode (Help)

Define_keycode (CAMERA)

};

Note:

Position

Android 4.4 Previous version Frameworks/base/include/ui/keycodelabels.h

Android 4.4 in Framework/native/include/input/keycodelabels.h

Android5.0 later in Framework/native/include/input/inputeventlabels.h

(2) definition KeyCode

a:native definition ( Keycodes.h )

enum {

.........

Akeycode_help = 259,

Akeycode_camera = 260

};

Note:

1 ) Location: Frameworks/base/include/android/keycodes.h

2 The value of the keycode defined here is the position (index) of the above key label defined in the Keycodes array, otherwise the error will be mapped

B : JAVA definition ( Keyevent.java Defining key Values )

public static final int keycode_help = 259;

public static final int keycode_camera = 260;

Modify Last_keycode

private static final int last_keycode = Keycode_camera;

Note:

1 ) Location : Frameworks/base/core/java/android/view/keyevent.java

2 The key code here must be consistent with the native definition

C : Resource file ( Attrs.xml ) to add KeyCode

Note:

1 ) Location : Frameworks\base\core\res\res\values\attrs.xml

Affecting the API you need to call make Update-api and then you can use it.

Iii. Issues Debug

Key Mapping error or Unknown , the troubleshooting steps are as follows:

    • Use GetEvent to confirm whether the driver reported the key value, is correct
    • Do you want to see the KL file name correctly? "See 1.2.A"
    • See if the KL file is loaded correctly, Dumpsys input to see if Keylayoutfile is correct
    • See if the key code defined by native corresponds to the position of the key label in the keycodes[] array.
    • See if Java layer Key code definition is consistent with native definition

Dumpsys Input See Keylayoutfile as follows:

2:abcxxxx

classes:0x00000001

Path:/dev/input/event7

Descriptor:0ea3e722ddb6fa78cd53a54fc262828fb3df6ca7

Location:alsa

controllernumber:0

UniqueId:

identifier:bus=0x0000, vendor=0x0000, product=0x0000, version=0x0000

keylayoutfile: /system/usr/keylayout/abcxxxx.kl

Keycharactermapfile:/SYSTEM/USR/KEYCHARS/GENERIC.KCM

ConfigurationFile:

Havekeyboardlayoutoverlay:false

Android Add (Keyboard) button

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.