当前位置: 首页>>代码示例>>Java>>正文


Java KeyEvent.isPrintingKey方法代码示例

本文整理汇总了Java中android.view.KeyEvent.isPrintingKey方法的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent.isPrintingKey方法的具体用法?Java KeyEvent.isPrintingKey怎么用?Java KeyEvent.isPrintingKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.view.KeyEvent的用法示例。


在下文中一共展示了KeyEvent.isPrintingKey方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: keyEventToPrintableChar

import android.view.KeyEvent; //导入方法依赖的package包/类
/**
 * Maps shortcut keys and Android keycodes to printable characters.
 * Note that whitespace is considered printable.
 * 
 * @param event The KeyEvent to interpret
 * @return The printable character the event represents, 
 * 	or Language.NULL_CHAR if the event does not represent a printable char
 */
public static char keyEventToPrintableChar(KeyEvent event){
	char c = Language.NULL_CHAR;

   	// convert tab, backspace, newline and space keycodes to standard ASCII values
   	if (isNewline(event)){
   		c = Language.NEWLINE;
       }
   	else if (isBackspace(event)){
   		c = Language.BACKSPACE;
       }
	// This should be before the check for isSpace() because the
   	// shortcut for TAB uses the SPACE key.
   	else if (isTab(event)){
   		c = Language.TAB;
       }
   	else if (isSpace(event)){
   		c = ' ';
       }
   	else if (event.isPrintingKey()){
   		c = (char) event.getUnicodeChar(event.getMetaState());
   	}
   	
	return c;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:33,代码来源:KeysInterpreter.java

示例2: onKey

import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {

    // This handles the hardware keyboard input
    if (event.isPrintingKey() || keyCode == KeyEvent.KEYCODE_SPACE) {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            ic.commitText(String.valueOf((char) event.getUnicodeChar()), 1);
        }
        return true;
    }

    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        SDLActivity.onNativeKeyDown(keyCode);
        return true;
    } else if (event.getAction() == KeyEvent.ACTION_UP) {
        SDLActivity.onNativeKeyUp(keyCode);
        return true;
    }

    return false;
}
 
开发者ID:jomof,项目名称:cdep-android-studio-freetype-sample,代码行数:22,代码来源:SDLActivity.java

示例3: sendKeyEvent

import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public boolean sendKeyEvent(KeyEvent event) {

    /*
     * This handles the keycodes from soft keyboard (and IME-translated
     * input from hardkeyboard)
     */
    int keyCode = event.getKeyCode();
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        if (event.isPrintingKey() || keyCode == KeyEvent.KEYCODE_SPACE) {
            commitText(String.valueOf((char) event.getUnicodeChar()), 1);
        }
        SDLActivity.onNativeKeyDown(keyCode);
        return true;
    } else if (event.getAction() == KeyEvent.ACTION_UP) {

        SDLActivity.onNativeKeyUp(keyCode);
        return true;
    }
    return super.sendKeyEvent(event);
}
 
开发者ID:jomof,项目名称:cdep-android-studio-freetype-sample,代码行数:22,代码来源:SDLActivity.java

示例4: dispatchKeyEvent

import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    boolean retVal = super.dispatchKeyEvent(event);
    if (retVal && mUrlHasFocus && mUrlFocusedWithoutAnimations
            && event.getAction() == KeyEvent.ACTION_DOWN && event.isPrintingKey()
            && event.hasNoModifiers()) {
        handleUrlFocusAnimation(mUrlHasFocus);
    }
    return retVal;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:11,代码来源:LocationBarLayout.java

示例5: onKey

import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
    int action = keyEvent.getAction();

    // Work-around for spurious key event from IME, bug #1639445
    if(action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
        return true; // eat it
    }

    if(keyEvent.getUnicodeChar() == '=') {
        if(action == KeyEvent.ACTION_UP) {
            mHandler.onEnter();
        }
        return true;
    }

    if(keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP && keyCode != KeyEvent.KEYCODE_DPAD_DOWN
            && keyCode != KeyEvent.KEYCODE_ENTER) {
        if(keyEvent.isPrintingKey() && action == KeyEvent.ACTION_UP) {
            // Tell the handler that text was updated.
            mHandler.onTextChanged();
        }
        return false;
    }

    /*
     * We should act on KeyEvent.ACTION_DOWN, but strangely sometimes the
     * DOWN event isn't received, only the UP. So the workaround is to act
     * on UP... http://b/issue?id=1022478
     */

    if(action == KeyEvent.ACTION_UP) {
        switch(keyCode) {
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            mHandler.onEnter();
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            mHandler.onUp();
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            mHandler.onDown();
            break;
        }
    }
    return true;
}
 
开发者ID:gigabytedevelopers,项目名称:CalcMate,代码行数:50,代码来源:EventListener.java

示例6: decodeHardwareKey

import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public Event decodeHardwareKey(final KeyEvent keyEvent) {
    // KeyEvent#getUnicodeChar() does not exactly returns a unicode char, but rather a value
    // that includes both the unicode char in the lower 21 bits and flags in the upper bits,
    // hence the name "codePointAndFlags". {@see KeyEvent#getUnicodeChar()} for more info.
    final int codePointAndFlags = keyEvent.getUnicodeChar();
    // The keyCode is the abstraction used by the KeyEvent to represent different keys that
    // do not necessarily map to a unicode character. This represents a physical key, like
    // the key for 'A' or Space, but also Backspace or Ctrl or Caps Lock.
    final int keyCode = keyEvent.getKeyCode();
    final boolean isKeyRepeat = (0 != keyEvent.getRepeatCount());
    if (KeyEvent.KEYCODE_DEL == keyCode) {
        return Event.createHardwareKeypressEvent(Event.NOT_A_CODE_POINT, Constants.CODE_DELETE,
                null /* next */, isKeyRepeat);
    }
    if (keyEvent.isPrintingKey() || KeyEvent.KEYCODE_SPACE == keyCode
            || KeyEvent.KEYCODE_ENTER == keyCode) {
        if (0 != (codePointAndFlags & KeyCharacterMap.COMBINING_ACCENT)) {
            // A dead key.
            return Event.createDeadEvent(
                    codePointAndFlags & KeyCharacterMap.COMBINING_ACCENT_MASK, keyCode,
                    null /* next */);
        }
        if (KeyEvent.KEYCODE_ENTER == keyCode) {
            // The Enter key. If the Shift key is not being pressed, this should send a
            // CODE_ENTER to trigger the action if any, or a carriage return otherwise. If the
            // Shift key is being pressed, this should send a CODE_SHIFT_ENTER and let
            // Latin IME decide what to do with it.
            if (keyEvent.isShiftPressed()) {
                return Event.createHardwareKeypressEvent(Event.NOT_A_CODE_POINT,
                        Constants.CODE_SHIFT_ENTER, null /* next */, isKeyRepeat);
            }
            return Event.createHardwareKeypressEvent(Constants.CODE_ENTER, keyCode,
                    null /* next */, isKeyRepeat);
        }
        // If not Enter, then this is just a regular keypress event for a normal character
        // that can be committed right away, taking into account the current state.
        return Event.createHardwareKeypressEvent(codePointAndFlags, keyCode, null /* next */,
                isKeyRepeat);
    }
    return Event.createNotHandledEvent();
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:43,代码来源:HardwareKeyboardEventDecoder.java

示例7: onKeyDown

import android.view.KeyEvent; //导入方法依赖的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;
}
 
开发者ID:NeoTerm,项目名称:NeoTerm,代码行数:77,代码来源:TerminalView.java


注:本文中的android.view.KeyEvent.isPrintingKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。