Example usage for android.view KeyEvent KEYCODE_9

List of usage examples for android.view KeyEvent KEYCODE_9

Introduction

In this page you can find the example usage for android.view KeyEvent KEYCODE_9.

Prototype

int KEYCODE_9

To view the source code for android.view KeyEvent KEYCODE_9.

Click Source Link

Document

Key code constant: '9' key.

Usage

From source file:com.customdatepicker.time.TimePickerDialog.java

/**
 * For keyboard mode, processes key events.
 * @param keyCode the pressed key./*www .  j  av  a2s.c o  m*/
 * @return true if the key was successfully processed, false otherwise.
 */
private boolean processKeyUp(int keyCode) {
    if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) {
        if (isCancelable())
            dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_TAB) {
        if (mInKbMode) {
            if (isTypedTimeFullyLegal()) {
                finishKbMode(true);
            }
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_ENTER) {
        if (mInKbMode) {
            if (!isTypedTimeFullyLegal()) {
                return true;
            }
            finishKbMode(false);
        }
        if (mCallback != null) {
            mCallback.onTimeSet(this, mTimePicker.getHours(), mTimePicker.getMinutes(),
                    mTimePicker.getSeconds());
        }
        dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DEL) {
        if (mInKbMode) {
            if (!mTypedTimes.isEmpty()) {
                int deleted = deleteLastTypedKey();
                String deletedKeyStr;
                if (deleted == getAmOrPmKeyCode(AM)) {
                    deletedKeyStr = mAmText;
                } else if (deleted == getAmOrPmKeyCode(PM)) {
                    deletedKeyStr = mPmText;
                } else {
                    deletedKeyStr = String.format("%d", getValFromKeyCode(deleted));
                }
                Utils.tryAccessibilityAnnounce(mTimePicker, String.format(mDeletedKeyFormat, deletedKeyStr));
                updateDisplay(true);
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1 || keyCode == KeyEvent.KEYCODE_2
            || keyCode == KeyEvent.KEYCODE_3 || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
            || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7 || keyCode == KeyEvent.KEYCODE_8
            || keyCode == KeyEvent.KEYCODE_9
            || (!mIs24HourMode && (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) {
        if (!mInKbMode) {
            if (mTimePicker == null) {
                // Something's wrong, because time picker should definitely not be null.
                Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null.");
                return true;
            }
            mTypedTimes.clear();
            tryStartingKbMode(keyCode);
            return true;
        }
        // We're already in keyboard mode.
        if (addKeyIfLegal(keyCode)) {
            updateDisplay(false);
        }
        return true;
    }
    return false;
}

From source file:nu.yona.timepicker.time.TimePickerDialog.java

/**
 * For keyboard mode, processes key events.
 *
 * @param keyCode the pressed key./* ww w .j a v  a2  s .c  o  m*/
 * @return true if the key was successfully processed, false otherwise.
 */
private boolean processKeyUp(int keyCode) {
    if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) {
        if (isCancelable())
            dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_TAB) {
        if (mInKbMode) {
            if (isTypedTimeFullyLegal()) {
                finishKbMode(true);
            }
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_ENTER) {
        if (mInKbMode) {
            if (!isTypedTimeFullyLegal()) {
                return true;
            }
            finishKbMode(false);
        }
        if (mCallback != null) {
            mCallback.onTimeSet(mTimePicker, mTimePicker.getHours(), mTimePicker.getMinutes(),
                    mTimePicker.getSeconds());
        }
        dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DEL) {
        if (mInKbMode) {
            if (!mTypedTimes.isEmpty()) {
                int deleted = deleteLastTypedKey();
                String deletedKeyStr;
                if (deleted == getAmOrPmKeyCode(AM)) {
                    deletedKeyStr = mAmText;

                } else if (deleted == getAmOrPmKeyCode(PM)) {
                    deletedKeyStr = mPmText;
                } else {
                    deletedKeyStr = String.format("%d", getValFromKeyCode(deleted));
                }
                Utils.tryAccessibilityAnnounce(mTimePicker, String.format(mDeletedKeyFormat, deletedKeyStr));
                updateDisplay(true);
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1 || keyCode == KeyEvent.KEYCODE_2
            || keyCode == KeyEvent.KEYCODE_3 || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
            || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7 || keyCode == KeyEvent.KEYCODE_8
            || keyCode == KeyEvent.KEYCODE_9
            || (!mIs24HourMode && (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) {
        if (!mInKbMode) {
            if (mTimePicker == null) {
                // Something's wrong, because time picker should definitely not be null.
                Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null.");
                return true;
            }
            mTypedTimes.clear();
            tryStartingKbMode(keyCode);
            return true;
        }
        // We're already in keyboard mode.
        if (addKeyIfLegal(keyCode)) {
            updateDisplay(false);
        }
        return true;
    }
    return false;
}

From source file:com.customdatepicker.time.TimePickerDialog.java

/**
 * Create a tree for deciding what keys can legally be typed.
 *//* w  w  w. j  a v a2  s. co  m*/
private void generateLegalTimesTree() {
    // Create a quick cache of numbers to their keycodes.
    int k0 = KeyEvent.KEYCODE_0;
    int k1 = KeyEvent.KEYCODE_1;
    int k2 = KeyEvent.KEYCODE_2;
    int k3 = KeyEvent.KEYCODE_3;
    int k4 = KeyEvent.KEYCODE_4;
    int k5 = KeyEvent.KEYCODE_5;
    int k6 = KeyEvent.KEYCODE_6;
    int k7 = KeyEvent.KEYCODE_7;
    int k8 = KeyEvent.KEYCODE_8;
    int k9 = KeyEvent.KEYCODE_9;

    // The root of the tree doesn't contain any numbers.
    mLegalTimesTree = new Node();

    // In case we're only allowing hours
    if (!mEnableMinutes && mIs24HourMode) {
        // The first digit may be 0-1
        Node firstDigit = new Node(k0, k1);
        mLegalTimesTree.addChild(firstDigit);

        // When the first digit is 0-1, the second digit may be 0-9
        Node secondDigit = new Node(k0, k1, k2, k3, k4, k5, k6, k7, k8, k9);
        firstDigit.addChild(secondDigit);

        // The first digit may be 2
        firstDigit = new Node(k2);
        mLegalTimesTree.addChild(firstDigit);

        // When the first digit is 2, the second digit may be 0-3
        secondDigit = new Node(k0, k1, k2, k3);
        firstDigit.addChild(secondDigit);
        return;
    }
    if (!mEnableMinutes && !mIs24HourMode) {
        // We'll need to use the AM/PM node a lot.
        // Set up AM and PM to respond to "a" and "p".
        Node ampm = new Node(getAmOrPmKeyCode(AM), getAmOrPmKeyCode(PM));

        // The first digit may be 1
        Node firstDigit = new Node(k1);
        mLegalTimesTree.addChild(firstDigit);

        // If the first digit is 1, the second one may be am/pm 1pm
        firstDigit.addChild(ampm);
        // If the first digit is 1, the second digit may be 0-2
        Node secondDigit = new Node(k0, k1, k2);
        firstDigit.addChild(secondDigit);
        secondDigit.addChild(ampm);

        // The first digit may be 2-9
        firstDigit = new Node(k2, k3, k4, k5, k6, k7, k8, k9);
        mLegalTimesTree.addChild(firstDigit);
        firstDigit.addChild(ampm);
        return;
    }

    // In case minutes are allowed
    if (mIs24HourMode) {
        // We'll be re-using these nodes, so we'll save them.
        Node minuteFirstDigit = new Node(k0, k1, k2, k3, k4, k5);
        Node minuteSecondDigit = new Node(k0, k1, k2, k3, k4, k5, k6, k7, k8, k9);
        // The first digit must be followed by the second digit.
        minuteFirstDigit.addChild(minuteSecondDigit);

        if (mEnableSeconds) {
            Node secondsFirstDigit = new Node(k0, k1, k2, k3, k4, k5);
            Node secondsSecondDigit = new Node(k0, k1, k2, k3, k4, k5, k6, k7, k8, k9);
            secondsFirstDigit.addChild(secondsSecondDigit);

            // Minutes can be followed by seconds.
            minuteSecondDigit.addChild(secondsFirstDigit);
        }

        // The first digit may be 0-1.
        Node firstDigit = new Node(k0, k1);
        mLegalTimesTree.addChild(firstDigit);

        // When the first digit is 0-1, the second digit may be 0-5.
        Node secondDigit = new Node(k0, k1, k2, k3, k4, k5);
        firstDigit.addChild(secondDigit);
        // We may now be followed by the first minute digit. E.g. 00:09, 15:58.
        secondDigit.addChild(minuteFirstDigit);

        // When the first digit is 0-1, and the second digit is 0-5, the third digit may be 6-9.
        Node thirdDigit = new Node(k6, k7, k8, k9);
        // The time must now be finished. E.g. 0:55, 1:08.
        secondDigit.addChild(thirdDigit);

        // When the first digit is 0-1, the second digit may be 6-9.
        secondDigit = new Node(k6, k7, k8, k9);
        firstDigit.addChild(secondDigit);
        // We must now be followed by the first minute digit. E.g. 06:50, 18:20.
        secondDigit.addChild(minuteFirstDigit);

        // The first digit may be 2.
        firstDigit = new Node(k2);
        mLegalTimesTree.addChild(firstDigit);

        // When the first digit is 2, the second digit may be 0-3.
        secondDigit = new Node(k0, k1, k2, k3);
        firstDigit.addChild(secondDigit);
        // We must now be followed by the first minute digit. E.g. 20:50, 23:09.
        secondDigit.addChild(minuteFirstDigit);

        // When the first digit is 2, the second digit may be 4-5.
        secondDigit = new Node(k4, k5);
        firstDigit.addChild(secondDigit);
        // We must now be followd by the last minute digit. E.g. 2:40, 2:53.
        secondDigit.addChild(minuteSecondDigit);

        // The first digit may be 3-9.
        firstDigit = new Node(k3, k4, k5, k6, k7, k8, k9);
        mLegalTimesTree.addChild(firstDigit);
        // We must now be followed by the first minute digit. E.g. 3:57, 8:12.
        firstDigit.addChild(minuteFirstDigit);
    } else {
        // We'll need to use the AM/PM node a lot.
        // Set up AM and PM to respond to "a" and "p".
        Node ampm = new Node(getAmOrPmKeyCode(AM), getAmOrPmKeyCode(PM));

        // Seconds will be used a few times as well, if enabled.
        Node secondsFirstDigit = new Node(k0, k1, k2, k3, k4, k5);
        Node secondsSecondDigit = new Node(k0, k1, k2, k3, k4, k5, k6, k7, k8, k9);
        secondsSecondDigit.addChild(ampm);
        secondsFirstDigit.addChild(secondsSecondDigit);

        // The first hour digit may be 1.
        Node firstDigit = new Node(k1);
        mLegalTimesTree.addChild(firstDigit);
        // We'll allow quick input of on-the-hour times. E.g. 1pm.
        firstDigit.addChild(ampm);

        // When the first digit is 1, the second digit may be 0-2.
        Node secondDigit = new Node(k0, k1, k2);
        firstDigit.addChild(secondDigit);
        // Also for quick input of on-the-hour times. E.g. 10pm, 12am.
        secondDigit.addChild(ampm);

        // When the first digit is 1, and the second digit is 0-2, the third digit may be 0-5.
        Node thirdDigit = new Node(k0, k1, k2, k3, k4, k5);
        secondDigit.addChild(thirdDigit);
        // The time may be finished now. E.g. 1:02pm, 1:25am.
        thirdDigit.addChild(ampm);

        // When the first digit is 1, the second digit is 0-2, and the third digit is 0-5,
        // the fourth digit may be 0-9.
        Node fourthDigit = new Node(k0, k1, k2, k3, k4, k5, k6, k7, k8, k9);
        thirdDigit.addChild(fourthDigit);
        // The time must be finished now, when seconds are disabled. E.g. 10:49am, 12:40pm.
        fourthDigit.addChild(ampm);

        // When the first digit is 1, the second digit is 0-2, and the third digit is 0-5,
        // and fourth digit is 0-9, we may add seconds if enabled.
        if (mEnableSeconds) {
            // The time must be finished now. E.g. 10:49:01am, 12:40:59pm.
            fourthDigit.addChild(secondsFirstDigit);
        }

        // When the first digit is 1, and the second digit is 0-2, the third digit may be 6-9.
        thirdDigit = new Node(k6, k7, k8, k9);
        secondDigit.addChild(thirdDigit);
        // The time must be finished now. E.g. 1:08am, 1:26pm.
        thirdDigit.addChild(ampm);

        // When the first digit is 1, and the second digit is 0-2, and the third digit is 6-9,
        // we may add seconds is enabled.
        if (mEnableSeconds) {
            // The time must be finished now. E.g. 1:08:01am, 1:26:59pm.
            thirdDigit.addChild(secondsFirstDigit);
        }

        // When the first digit is 1, the second digit may be 3-5.
        secondDigit = new Node(k3, k4, k5);
        firstDigit.addChild(secondDigit);

        // When the first digit is 1, and the second digit is 3-5, the third digit may be 0-9.
        thirdDigit = new Node(k0, k1, k2, k3, k4, k5, k6, k7, k8, k9);
        secondDigit.addChild(thirdDigit);
        // The time must be finished now if seconds are disabled. E.g. 1:39am, 1:50pm.
        thirdDigit.addChild(ampm);

        // When the first digit is 1, and the second digit is 3-5, and the third digit is 0-9,
        // we may add seconds if enabled.
        if (mEnableSeconds) {
            // The time must be finished now. E.g. 1:39:01am, 1:50:59pm.
            thirdDigit.addChild(secondsFirstDigit);
        }

        // The hour digit may be 2-9.
        firstDigit = new Node(k2, k3, k4, k5, k6, k7, k8, k9);
        mLegalTimesTree.addChild(firstDigit);
        // We'll allow quick input of on-the-hour-times. E.g. 2am, 5pm.
        firstDigit.addChild(ampm);

        // When the first digit is 2-9, the second digit may be 0-5.
        secondDigit = new Node(k0, k1, k2, k3, k4, k5);
        firstDigit.addChild(secondDigit);

        // When the first digit is 2-9, and the second digit is 0-5, the third digit may be 0-9.
        thirdDigit = new Node(k0, k1, k2, k3, k4, k5, k6, k7, k8, k9);
        secondDigit.addChild(thirdDigit);
        // The time must be finished now. E.g. 2:57am, 9:30pm.
        thirdDigit.addChild(ampm);

        // When the first digit is 2-9, and the second digit is 0-5, and third digit is 0-9, we
        // may add seconds if enabled.
        if (mEnableSeconds) {
            // The time must be finished now. E.g. 2:57:01am, 9:30:59pm.
            thirdDigit.addChild(secondsFirstDigit);
        }
    }
}

From source file:org.distantshoresmedia.keyboard.LatinIME.java

private void sendSpecialKey(int code) {
    if (!isConnectbot()) {
        commitTyped(getCurrentInputConnection(), true);
        sendModifiedKeyDownUp(code);//  w  w  w.j a  va  2 s . c o m
        return;
    }

    // TODO(klausw): properly support xterm sequences for Ctrl/Alt modifiers?
    // See http://slackware.osuosl.org/slackware-12.0/source/l/ncurses/xterm.terminfo
    // and the output of "$ infocmp -1L". Support multiple sets, and optional 
    // true numpad keys?
    if (ESC_SEQUENCES == null) {
        ESC_SEQUENCES = new HashMap<Integer, String>();
        CTRL_SEQUENCES = new HashMap<Integer, Integer>();

        // VT escape sequences without leading Escape
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_HOME, "[1~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_END, "[4~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_PAGE_UP, "[5~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_PAGE_DOWN, "[6~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F1, "OP");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F2, "OQ");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F3, "OR");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F4, "OS");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F5, "[15~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F6, "[17~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F7, "[18~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F8, "[19~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F9, "[20~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F10, "[21~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F11, "[23~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F12, "[24~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FORWARD_DEL, "[3~");
        ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_INSERT, "[2~");

        // Special ConnectBot hack: Ctrl-1 to Ctrl-0 for F1-F10.
        CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F1, KeyEvent.KEYCODE_1);
        CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F2, KeyEvent.KEYCODE_2);
        CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F3, KeyEvent.KEYCODE_3);
        CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F4, KeyEvent.KEYCODE_4);
        CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F5, KeyEvent.KEYCODE_5);
        CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F6, KeyEvent.KEYCODE_6);
        CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F7, KeyEvent.KEYCODE_7);
        CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F8, KeyEvent.KEYCODE_8);
        CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F9, KeyEvent.KEYCODE_9);
        CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F10, KeyEvent.KEYCODE_0);

        // Natively supported by ConnectBot
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_UP, "OA");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_DOWN, "OB");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_LEFT, "OD");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_RIGHT, "OC");

        // No VT equivalents?
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_CENTER, "");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_SYSRQ, "");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_BREAK, "");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_NUM_LOCK, "");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_SCROLL_LOCK, "");
    }
    InputConnection ic = getCurrentInputConnection();
    Integer ctrlseq = null;
    if (mConnectbotTabHack) {
        ctrlseq = CTRL_SEQUENCES.get(code);
    }
    String seq = ESC_SEQUENCES.get(code);

    if (ctrlseq != null) {
        if (mModAlt) {
            // send ESC prefix for "Alt"
            ic.commitText(Character.toString((char) 27), 1);
        }
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER));
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER));
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, ctrlseq));
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, ctrlseq));
    } else if (seq != null) {
        if (mModAlt) {
            // send ESC prefix for "Alt"
            ic.commitText(Character.toString((char) 27), 1);
        }
        // send ESC prefix of escape sequence
        ic.commitText(Character.toString((char) 27), 1);
        ic.commitText(seq, 1);
    } else {
        // send key code, let connectbot handle it
        sendDownUpKeyEvents(code);
    }
    handleModifierKeysUp(false, false);
}

From source file:org.pocketworkstation.pckeyboard.LatinIME.java

private void sendSpecialKey(int code) {
    if (!isConnectbot()) {
        commitTyped(getCurrentInputConnection(), true);
        sendModifiedKeyDownUp(code);/*from ww w  .j  a  v  a 2 s  . c om*/
        return;
    }

    // TODO(klausw): properly support xterm sequences for Ctrl/Alt modifiers?
    // See http://slackware.osuosl.org/slackware-12.0/source/l/ncurses/xterm.terminfo
    // and the output of "$ infocmp -1L". Support multiple sets, and optional 
    // true numpad keys?
    if (ESC_SEQUENCES == null) {
        ESC_SEQUENCES = new HashMap<Integer, String>();
        CTRL_SEQUENCES = new HashMap<Integer, Integer>();

        // VT escape sequences without leading Escape
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_HOME, "[1~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_END, "[4~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_PAGE_UP, "[5~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_PAGE_DOWN, "[6~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F1, "OP");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F2, "OQ");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F3, "OR");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F4, "OS");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F5, "[15~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F6, "[17~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F7, "[18~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F8, "[19~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F9, "[20~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F10, "[21~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F11, "[23~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F12, "[24~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FORWARD_DEL, "[3~");
        ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_INSERT, "[2~");

        // Special ConnectBot hack: Ctrl-1 to Ctrl-0 for F1-F10.
        CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F1, KeyEvent.KEYCODE_1);
        CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F2, KeyEvent.KEYCODE_2);
        CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F3, KeyEvent.KEYCODE_3);
        CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F4, KeyEvent.KEYCODE_4);
        CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F5, KeyEvent.KEYCODE_5);
        CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F6, KeyEvent.KEYCODE_6);
        CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F7, KeyEvent.KEYCODE_7);
        CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F8, KeyEvent.KEYCODE_8);
        CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F9, KeyEvent.KEYCODE_9);
        CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F10, KeyEvent.KEYCODE_0);

        // Natively supported by ConnectBot
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_UP, "OA");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_DOWN, "OB");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_LEFT, "OD");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_RIGHT, "OC");

        // No VT equivalents?
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_CENTER, "");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_SYSRQ, "");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_BREAK, "");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_NUM_LOCK, "");
        // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_SCROLL_LOCK, "");
    }
    InputConnection ic = getCurrentInputConnection();
    Integer ctrlseq = null;
    if (mConnectbotTabHack) {
        ctrlseq = CTRL_SEQUENCES.get(code);
    }
    String seq = ESC_SEQUENCES.get(code);

    if (ctrlseq != null) {
        if (mModAlt) {
            // send ESC prefix for "Alt"
            ic.commitText(Character.toString((char) 27), 1);
        }
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER));
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER));
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, ctrlseq));
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, ctrlseq));
    } else if (seq != null) {
        if (mModAlt) {
            // send ESC prefix for "Alt"
            ic.commitText(Character.toString((char) 27), 1);
        }
        // send ESC prefix of escape sequence
        ic.commitText(Character.toString((char) 27), 1);
        ic.commitText(seq, 1);
    } else {
        // send key code, let connectbot handle it
        sendDownUpKeyEvents(code);
    }
    handleModifierKeysUp(false, false);
}

From source file:org.brandroid.openmanager.activities.OpenExplorer.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (DEBUG)//from w w  w .  ja  v a 2s  .c o  m
        Logger.LogDebug("OpenExplorer.onKeyUp(" + keyCode + "," + event + ")");
    if (event.getAction() != KeyEvent.ACTION_UP)
        return super.onKeyUp(keyCode, event);
    if (MenuUtils.getMenuShortcut(event) != null) {
        if (getCurrentFocus() != null) {
            View cf = getCurrentFocus();
            if (cf instanceof TextView)
                return false;
        }
        MenuItem item = MenuUtils.getMenuShortcut(event);
        if (item != null)
            if (onOptionsItemSelected(item)) {
                showToast(item.getTitle(), Toast.LENGTH_SHORT);
                return true;
            }
    }
    if (keyCode == KeyEvent.KEYCODE_MENU && USE_PRETTY_MENUS) {
        View more = findViewById(R.id.menu_more);
        if (more != null && more.isShown() && more.isClickable() && more.performClick()) {
            Logger.LogDebug("!SHOULD BE HERE!");
            return true;
        } else {
            Logger.LogWarning("Couldn't find \"More Menu\"!");
            MenuBuilder menu = new MenuBuilder(this);
            getSelectedFragment().onCreateOptionsMenu(menu, getMenuInflater());
            getMenuInflater().inflate(R.menu.global, menu);
            onPrepareOptionsMenu(menu);
            showMenu(menu, getCurrentFocus(), true);
        }
    } else if (keyCode == KeyEvent.KEYCODE_BOOKMARK) {
        OpenPath path = getDirContentFragment(false).getPath();
        if (mBookmarks.hasBookmark(path))
            addBookmark(path);
        else
            removeBookmark(path);
    } else if (keyCode >= KeyEvent.KEYCODE_1 && keyCode <= KeyEvent.KEYCODE_9) {
        int pos = keyCode - KeyEvent.KEYCODE_1;
        if (mToolbarButtons != null) {
            if (pos < mToolbarButtons.getChildCount() && mToolbarButtons.getChildAt(pos).performClick())
                return true;
            return false;
        }
        if (mOptsMenu != null && pos < mOptsMenu.size())
            return onOptionsItemSelected(mOptsMenu.getItem(pos));
        if (mMainMenu != null && pos < mMainMenu.size())
            return onOptionsItemSelected(mMainMenu.getItem(pos));
    }
    /*
    if (keyCode == KeyEvent.KEYCODE_BACK) {
       if (mBackQuit) {
    return super.onKeyUp(keyCode, event);
       } else {
    Toast.makeText(this, "Press back again to quit", Toast.LENGTH_SHORT).show();
    mBackQuit = true;
    return true;
       }      
    }*/
    return super.onKeyUp(keyCode, event);
}