Java 怎么 get char_Java KeyCharacterMap.getDeadChar方法代码示例

import android.view.KeyCharacterMap; //导入方法依赖的package包/类

@Override

public boolean onKeyDown(int keyCode, KeyEvent event) {

if (LOG_KEY_EVENTS)

Log.i(EmulatorDebug.LOG_TAG, "onKeyDown(keyCode=" + keyCode + ", isSystem()=" + event.isSystem() + ", event=" + event + ")");

if (mEmulator == null) return true;

if (mClient.onKeyDown(keyCode, event, mTermSession)) {

invalidate();

return true;

} else if (event.isSystem() && (!mClient.shouldBackButtonBeMappedToEscape() || keyCode != KeyEvent.KEYCODE_BACK)) {

return super.onKeyDown(keyCode, event);

} else if (event.getAction() == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {

mTermSession.write(event.getCharacters());

return true;

}

final int metaState = event.getMetaState();

final boolean controlDownFromEvent = event.isCtrlPressed();

final boolean leftAltDownFromEvent = (metaState & KeyEvent.META_ALT_LEFT_ON) != 0;

final boolean rightAltDownFromEvent = (metaState & KeyEvent.META_ALT_RIGHT_ON) != 0;

int keyMod = 0;

if (controlDownFromEvent) keyMod |= KeyHandler.KEYMOD_CTRL;

if (event.isAltPressed()) keyMod |= KeyHandler.KEYMOD_ALT;

if (event.isShiftPressed()) keyMod |= KeyHandler.KEYMOD_SHIFT;

if (handleKeyCode(keyCode, keyMod)) {

if (LOG_KEY_EVENTS) Log.i(EmulatorDebug.LOG_TAG, "handleKeyCode() took key event");

return true;

}

// Clear Ctrl since we handle that ourselves:

int bitsToClear = KeyEvent.META_CTRL_MASK;

if (rightAltDownFromEvent) {

// Let right Alt/Alt Gr be used to compose characters.

} else {

// Use left alt to send to terminal (e.g. Left Alt+B to jump back a word), so remove:

bitsToClear |= KeyEvent.META_ALT_ON | KeyEvent.META_ALT_LEFT_ON;

}

int effectiveMetaState = event.getMetaState() & ~bitsToClear;

int result = event.getUnicodeChar(effectiveMetaState);

if (LOG_KEY_EVENTS)

Log.i(EmulatorDebug.LOG_TAG, "KeyEvent#getUnicodeChar(" + effectiveMetaState + ") returned: " + result);

if (result == 0) {

return true;

}

int oldCombiningAccent = mCombiningAccent;

if ((result & KeyCharacterMap.COMBINING_ACCENT) != 0) {

// If entered combining accent previously, write it out:

if (mCombiningAccent != 0)

inputCodePoint(mCombiningAccent, controlDownFromEvent, leftAltDownFromEvent);

mCombiningAccent = result & KeyCharacterMap.COMBINING_ACCENT_MASK;

} else {

if (mCombiningAccent != 0) {

int combinedChar = KeyCharacterMap.getDeadChar(mCombiningAccent, result);

if (combinedChar > 0) result = combinedChar;

mCombiningAccent = 0;

}

inputCodePoint(result, controlDownFromEvent, leftAltDownFromEvent);

}

if (mCombiningAccent != oldCombiningAccent) invalidate();

if (onAutoCompleteListener != null) {

if (event.isPrintingKey()) {

char printingChar = (char) event.getUnicodeChar(metaState);

if (printingChar != '\b') {

// ASCII chars

onAutoCompleteListener.onCompletionRequired(new String(new char[]{printingChar}));

}

}

}

return true;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值