android/frameworks/base/core/res/res/values/Vendor_0f30_Product_0008.kl
注意:0f30是该Input设备的VID,0008是设备的PID
key 88 BUTTON_A
key 87 MENU WAKE_DROPPED
key 68 SEARCH
key 67 EXPLORER
# EHK help key
key 66 DATASHEET
# EHK abc key
key 65 DICTIONARY
我们添加了两个按键key 65 和key 66,66和65这两个值是通过getevent命令打印转成十进制后的值
DATASHEET和DICTIONARY是我们自己定义的androidKeycode
2、在android Keycodes数组中加入我们新增加的keycode
a. android/frameworks/native/include/android/keycodes.h
AKEYCODE_MEDIA_AUDIO_TRACK = 222,
AKEYCODE_CAPTURE = 223,
AKEYCODE_DATASHEET = 224, // EHK HELP KEY
AKEYCODE_DICTIONARY = 225,
b.android/frameworks/native/include/input/KeycodeLabels.h
{ "CAPTURE", 222 },
{ "DATASHEET", 224 }, // EHK HELP KEY
{ "DICTIONARY", 225 },
c. android/frameworks/base/core/java/android/view/KeyEvent.java
names.append(KEYCODE_CAPTURE, "KEYCODE_CAPTURE");
names.append(KEYCODE_DATASHEET, "KEYCODE_DATASHEET"); // EHK help key
names.append(KEYCODE_DICTIONARY, "KEYCODE_DICTIONARY");
d. android/frameworks/base/core/res/res/values/attrs.xml
3、android/frameworks/base/core/java/android/view/inputmethod/InputMethodManager.java
这里添加按键响应的具体动作:
public int dispatchInputEvent(InputEvent event, Object token,
FinishedInputEventCallback callback, Handler handler) {
synchronized (mH) {
if (mCurMethod != null) {
if (event instanceof KeyEvent) {
KeyEvent keyEvent = (KeyEvent)event;
if (keyEvent.getAction() == KeyEvent.ACTION_DOWN
&& keyEvent.getKeyCode() == KeyEvent.KEYCODE_SYM
&& keyEvent.getRepeatCount() == 0) {
//showInputMethodPickerLocked();
return DISPATCH_HANDLED;
} else if (keyEvent.getAction() == KeyEvent.ACTION_DOWN
&& keyEvent.getKeyCode() == KeyEvent.KEYCODE_DATASHEET
&& keyEvent.getRepeatCount() == 0) {
Log.d(TAG,"zhanbing kbd button pressed");
toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
return DISPATCH_HANDLED;
}
}
if (DEBUG) Log.v(TAG, "DISPATCH INPUT EVENT: " + mCurMethod);
PendingEvent p = obtainPendingEventLocked(
event, token, mCurId, callback, handler);
if (mMainLooper.isCurrentThread()) {
// Already running on the IMM thread so we can send the event immediately.
return sendInputEventOnMainLooperLocked(p);
}
// Post the event to the IMM thread.
Message msg = mH.obtainMessage(MSG_SEND_INPUT_EVENT, p);
msg.setAsynchronous(true);
mH.sendMessage(msg);
return DISPATCH_IN_PROGRESS;
}else{
Log.d(TAG, "inputMethod be killed??? mCurId=" + mCurId+ "mWaitForBinding= " + mWaitForBinding);
Log.d(TAG, "mCurMethod= " +mCurMethod);
if((event instanceof KeyEvent) &&mWaitForBinding && mCurId!=null){
return DISPATCH_FORWARD;
}else if((mBindSequence==-1)&&(event instanceof KeyEvent) &&mCurId==null){
//connection cleared
return DISPATCH_FORWARD;
}
}
}