Example usage for android.view KeyEvent KEYCODE_DPAD_LEFT

List of usage examples for android.view KeyEvent KEYCODE_DPAD_LEFT

Introduction

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

Prototype

int KEYCODE_DPAD_LEFT

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

Click Source Link

Document

Key code constant: Directional Pad Left key.

Usage

From source file:android.support.v7.widget.SearchView.java

/**
 * React to the user typing while in the suggestions list. First, check for
 * action keys. If not handled, try refocusing regular characters into the
 * EditText./*  w ww.  ja  va2  s.  c  om*/
 */
private boolean onSuggestionsKey(View v, int keyCode, KeyEvent event) {
    // guard against possible race conditions (late arrival after dismiss)
    if (mSearchable == null) {
        return false;
    }
    if (mSuggestionsAdapter == null) {
        return false;
    }
    if (event.getAction() == KeyEvent.ACTION_DOWN && KeyEventCompat.hasNoModifiers(event)) {
        // First, check for enter or search (both of which we'll treat as a
        // "click")
        if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_SEARCH
                || keyCode == KeyEvent.KEYCODE_TAB) {
            int position = mSearchSrcTextView.getListSelection();
            return onItemClicked(position, KeyEvent.KEYCODE_UNKNOWN, null);
        }

        // Next, check for left/right moves, which we use to "return" the
        // user to the edit view
        if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
            // give "focus" to text editor, with cursor at the beginning if
            // left key, at end if right key
            // TODO: Reverse left/right for right-to-left languages, e.g.
            // Arabic
            int selPoint = (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) ? 0 : mSearchSrcTextView.length();
            mSearchSrcTextView.setSelection(selPoint);
            mSearchSrcTextView.setListSelection(0);
            mSearchSrcTextView.clearListSelection();
            HIDDEN_METHOD_INVOKER.ensureImeVisible(mSearchSrcTextView, true);

            return true;
        }

        // Next, check for an "up and out" move
        if (keyCode == KeyEvent.KEYCODE_DPAD_UP && 0 == mSearchSrcTextView.getListSelection()) {
            // TODO: restoreUserQuery();
            // let ACTV complete the move
            return false;
        }
    }
    return false;
}

From source file:com.nttec.everychan.ui.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_UP:
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (settings.scrollVolumeButtons) {
            try {
                Fragment currentFragment = MainApplication.getInstance().tabsSwitcher.currentFragment;
                if (currentFragment instanceof BoardFragment) {
                    BoardFragment boardFragment = (BoardFragment) currentFragment;
                    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP)
                        boardFragment.scrollUp();
                    else
                        boardFragment.scrollDown();
                    return true;
                }//from w w  w .j  av  a2  s.c  o m
            } catch (Exception e) {
                Logger.e(TAG, e);
            }
        }
        break;
    case KeyEvent.KEYCODE_BACK:
        if (onBack())
            return true;
        break;
    case KeyEvent.KEYCODE_DPAD_LEFT:
        if (focusActionBar())
            return true;
        break;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.yek.keyboard.anysoftkeyboard.AnySoftKeyboard.java

@Override
public boolean onKeyDown(final int keyEventKeyCode, @NonNull KeyEvent event) {
    InputConnection ic = getCurrentInputConnection();
    if (handleSelectionExpending(keyEventKeyCode, ic, mGlobalSelectionStartPosition, mGlobalCursorPosition))
        return true;
    final boolean shouldTranslateSpecialKeys = isInputViewShown();

    //greater than zero means it is a physical keyboard.
    //we also want to hide the view if it's a glyph (for example, not physical volume-up key)
    if (event.getDeviceId() > 0 && event.isPrintingKey())
        onPhysicalKeyboardKeyPressed();//w ww .  j  a  v a  2s  . c  om

    mHardKeyboardAction.initializeAction(event, mMetaState);

    switch (keyEventKeyCode) {
    /****
     * SPECIAL translated HW keys If you add new keys here, do not forget
     * to add to the
     */
    case KeyEvent.KEYCODE_CAMERA:
        if (shouldTranslateSpecialKeys && mAskPrefs.useCameraKeyForBackspaceBackword()) {
            handleBackWord(getCurrentInputConnection());
            return true;
        }
        // DO NOT DELAY CAMERA KEY with unneeded checks in default mark
        return super.onKeyDown(keyEventKeyCode, event);
    case KeyEvent.KEYCODE_FOCUS:
        if (shouldTranslateSpecialKeys && mAskPrefs.useCameraKeyForBackspaceBackword()) {
            handleDeleteLastCharacter(false);
            return true;
        }
        // DO NOT DELAY FOCUS KEY with unneeded checks in default mark
        return super.onKeyDown(keyEventKeyCode, event);
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (shouldTranslateSpecialKeys && mAskPrefs.useVolumeKeyForLeftRight()) {
            sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_LEFT);
            return true;
        }
        // DO NOT DELAY VOLUME UP KEY with unneeded checks in default
        // mark
        return super.onKeyDown(keyEventKeyCode, event);
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (shouldTranslateSpecialKeys && mAskPrefs.useVolumeKeyForLeftRight()) {
            sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_RIGHT);
            return true;
        }
        // DO NOT DELAY VOLUME DOWN KEY with unneeded checks in default
        // mark
        return super.onKeyDown(keyEventKeyCode, event);
    /****
     * END of SPECIAL translated HW keys code section
     */
    case KeyEvent.KEYCODE_BACK:
        if (event.getRepeatCount() == 0 && getInputView() != null) {
            if (getInputView().handleBack()) {
                // consuming the meta keys
                if (ic != null) {
                    // translated, so we also take care of the metakeys
                    ic.clearMetaKeyStates(Integer.MAX_VALUE);
                }
                mMetaState = 0;
                return true;
            }
        }
        break;
    case 0x000000cc:// API 14: KeyEvent.KEYCODE_LANGUAGE_SWITCH
        switchToNextPhysicalKeyboard(ic);
        return true;
    case KeyEvent.KEYCODE_SHIFT_LEFT:
    case KeyEvent.KEYCODE_SHIFT_RIGHT:
        if (event.isAltPressed() && Workarounds.isAltSpaceLangSwitchNotPossible()) {
            switchToNextPhysicalKeyboard(ic);
            return true;
        }
        // NOTE: letting it fall-through to the other meta-keys
    case KeyEvent.KEYCODE_ALT_LEFT:
    case KeyEvent.KEYCODE_ALT_RIGHT:
    case KeyEvent.KEYCODE_SYM:
        Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown before handle"));
        mMetaState = MyMetaKeyKeyListener.handleKeyDown(mMetaState, keyEventKeyCode, event);
        Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown after handle"));
        break;
    case KeyEvent.KEYCODE_SPACE:
        if ((event.isAltPressed() && !Workarounds.isAltSpaceLangSwitchNotPossible())
                || event.isShiftPressed()) {
            switchToNextPhysicalKeyboard(ic);
            return true;
        }
        // NOTE:
        // letting it fall through to the "default"
    default:

        // Fix issue 185, check if we should process key repeat
        if (!mAskPrefs.getUseRepeatingKeys() && event.getRepeatCount() > 0)
            return true;

        AnyKeyboard.HardKeyboardTranslator keyTranslator = (AnyKeyboard.HardKeyboardTranslator) getCurrentAlphabetKeyboard();
        if (getKeyboardSwitcher().isCurrentKeyboardPhysical() && keyTranslator != null) {
            // sometimes, the physical keyboard will delete input, and then add some.
            // we'll try to make it nice.
            if (ic != null)
                ic.beginBatchEdit();
            try {
                // issue 393, backword on the hw keyboard!
                if (mAskPrefs.useBackword() && keyEventKeyCode == KeyEvent.KEYCODE_DEL
                        && event.isShiftPressed()) {
                    handleBackWord(ic);
                    return true;
                } else {
                    // http://article.gmane.org/gmane.comp.handhelds.openmoko.android-freerunner/629
                    keyTranslator.translatePhysicalCharacter(mHardKeyboardAction, this);

                    if (mHardKeyboardAction.getKeyCodeWasChanged()) {
                        final int translatedChar = mHardKeyboardAction.getKeyCode();
                        // typing my own.
                        onKey(translatedChar, null, -1, new int[] { translatedChar }, true/*faking from UI*/);
                        // my handling we are at a regular key press, so we'll update
                        // our meta-state member
                        mMetaState = MyMetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState);
                        Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown after adjust - translated"));
                        return true;
                    }
                }
            } finally {
                if (ic != null)
                    ic.endBatchEdit();
            }
        }
        if (event.isPrintingKey()) {
            // we are at a regular key press, so we'll update our
            // meta-state
            // member
            mMetaState = MyMetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState);
            Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown after adjust"));
        }
    }
    return super.onKeyDown(keyEventKeyCode, event);
}

From source file:com.anysoftkeyboard.AnySoftKeyboard.java

@Override
public boolean onKeyDown(final int keyEventKeyCode, @NonNull KeyEvent event) {
    InputConnection ic = getCurrentInputConnection();
    if (handleSelectionExpending(keyEventKeyCode, ic, mGlobalSelectionStartPosition, mGlobalCursorPosition))
        return true;
    final boolean shouldTranslateSpecialKeys = isInputViewShown();

    //greater than zero means it is a physical keyboard.
    //we also want to hide the view if it's a glyph (for example, not physical volume-up key)
    if (event.getDeviceId() > 0 && event.isPrintingKey())
        onPhysicalKeyboardKeyPressed();//from   www .j av  a2  s. co  m

    mHardKeyboardAction.initializeAction(event, mMetaState);

    switch (keyEventKeyCode) {
    /****
     * SPECIAL translated HW keys If you add new keys here, do not forget
     * to add to the
     */
    case KeyEvent.KEYCODE_CAMERA:
        if (shouldTranslateSpecialKeys && mAskPrefs.useCameraKeyForBackspaceBackword()) {
            handleBackWord(getCurrentInputConnection());
            return true;
        }
        // DO NOT DELAY CAMERA KEY with unneeded checks in default mark
        return super.onKeyDown(keyEventKeyCode, event);
    case KeyEvent.KEYCODE_FOCUS:
        if (shouldTranslateSpecialKeys && mAskPrefs.useCameraKeyForBackspaceBackword()) {
            handleDeleteLastCharacter(false);
            return true;
        }
        // DO NOT DELAY FOCUS KEY with unneeded checks in default mark
        return super.onKeyDown(keyEventKeyCode, event);
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (shouldTranslateSpecialKeys && mAskPrefs.useVolumeKeyForLeftRight()) {
            sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_LEFT);
            return true;
        }
        // DO NOT DELAY VOLUME UP KEY with unneeded checks in default
        // mark
        return super.onKeyDown(keyEventKeyCode, event);
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (shouldTranslateSpecialKeys && mAskPrefs.useVolumeKeyForLeftRight()) {
            sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_RIGHT);
            return true;
        }
        // DO NOT DELAY VOLUME DOWN KEY with unneeded checks in default
        // mark
        return super.onKeyDown(keyEventKeyCode, event);
    /****
     * END of SPECIAL translated HW keys code section
     */
    case KeyEvent.KEYCODE_BACK:
        if (event.getRepeatCount() == 0 && getInputView() != null) {
            if (getInputView().handleBack()) {
                // consuming the meta keys
                if (ic != null) {
                    // translated, so we also take care of the metakeys
                    ic.clearMetaKeyStates(Integer.MAX_VALUE);
                }
                mMetaState = 0;
                return true;
            }
        }
        break;
    case 0x000000cc:// API 14: KeyEvent.KEYCODE_LANGUAGE_SWITCH
        switchToNextPhysicalKeyboard(ic);
        return true;
    case KeyEvent.KEYCODE_SHIFT_LEFT:
    case KeyEvent.KEYCODE_SHIFT_RIGHT:
        if (event.isAltPressed() && Workarounds.isAltSpaceLangSwitchNotPossible()) {
            switchToNextPhysicalKeyboard(ic);
            return true;
        }
        // NOTE: letting it fall-through to the other meta-keys
    case KeyEvent.KEYCODE_ALT_LEFT:
    case KeyEvent.KEYCODE_ALT_RIGHT:
    case KeyEvent.KEYCODE_SYM:
        Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown before handle"));
        mMetaState = MyMetaKeyKeyListener.handleKeyDown(mMetaState, keyEventKeyCode, event);
        Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown after handle"));
        break;
    case KeyEvent.KEYCODE_SPACE:
        if ((event.isAltPressed() && !Workarounds.isAltSpaceLangSwitchNotPossible())
                || event.isShiftPressed()) {
            switchToNextPhysicalKeyboard(ic);
            return true;
        }
        // NOTE:
        // letting it fall through to the "default"
    default:

        // Fix issue 185, check if we should process key repeat
        if (!mAskPrefs.getUseRepeatingKeys() && event.getRepeatCount() > 0)
            return true;

        HardKeyboardTranslator keyTranslator = (HardKeyboardTranslator) getCurrentAlphabetKeyboard();
        if (getKeyboardSwitcher().isCurrentKeyboardPhysical() && keyTranslator != null) {
            // sometimes, the physical keyboard will delete input, and then add some.
            // we'll try to make it nice.
            if (ic != null)
                ic.beginBatchEdit();
            try {
                // issue 393, backword on the hw keyboard!
                if (mAskPrefs.useBackword() && keyEventKeyCode == KeyEvent.KEYCODE_DEL
                        && event.isShiftPressed()) {
                    handleBackWord(ic);
                    return true;
                } else {
                    // http://article.gmane.org/gmane.comp.handhelds.openmoko.android-freerunner/629
                    keyTranslator.translatePhysicalCharacter(mHardKeyboardAction, this);

                    if (mHardKeyboardAction.getKeyCodeWasChanged()) {
                        final int translatedChar = mHardKeyboardAction.getKeyCode();
                        // typing my own.
                        onKey(translatedChar, null, -1, new int[] { translatedChar }, true/*faking from UI*/);
                        // my handling we are at a regular key press, so we'll update
                        // our meta-state member
                        mMetaState = MyMetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState);
                        Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown after adjust - translated"));
                        return true;
                    }
                }
            } finally {
                if (ic != null)
                    ic.endBatchEdit();
            }
        }
        if (event.isPrintingKey()) {
            // we are at a regular key press, so we'll update our
            // meta-state
            // member
            mMetaState = MyMetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState);
            Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown after adjust"));
        }
    }
    return super.onKeyDown(keyEventKeyCode, event);
}

From source file:android.support.v17.leanback.widget.GridWidgetTest.java

public void testNonFocusableHorizontal() throws Throwable {
    final int numItems = 200;
    final int startPos = 45;
    final int skips = 20;
    final int numColumns = 3;
    final int endPos = startPos + numColumns * (skips + 1);

    mInstrumentation = getInstrumentation();
    Intent intent = new Intent(mInstrumentation.getContext(), GridActivity.class);
    intent.putExtra(GridActivity.EXTRA_LAYOUT_RESOURCE_ID, R.layout.horizontal_grid);
    intent.putExtra(GridActivity.EXTRA_NUM_ITEMS, numItems);
    intent.putExtra(GridActivity.EXTRA_STAGGERED, false);
    mOrientation = BaseGridView.HORIZONTAL;
    mNumRows = numColumns;//from www . j a va  2  s. c o  m
    boolean[] focusable = new boolean[numItems];
    for (int i = 0; i < focusable.length; i++) {
        focusable[i] = true;
    }
    for (int i = startPos + mNumRows, j = 0; j < skips; i += mNumRows, j++) {
        focusable[i] = false;
    }
    intent.putExtra(GridActivity.EXTRA_ITEMS_FOCUSABLE, focusable);
    initActivity(intent);

    mGridView.setSelectedPositionSmooth(startPos);
    waitForScrollIdle(mVerifyLayout);

    if (mGridView.getLayoutDirection() == ViewGroup.LAYOUT_DIRECTION_RTL) {
        sendKeys(KeyEvent.KEYCODE_DPAD_LEFT);
    } else {
        sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT);
    }
    waitForScrollIdle(mVerifyLayout);
    assertEquals(endPos, mGridView.getSelectedPosition());

    if (mGridView.getLayoutDirection() == ViewGroup.LAYOUT_DIRECTION_RTL) {
        sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT);
    } else {
        sendKeys(KeyEvent.KEYCODE_DPAD_LEFT);
    }
    waitForScrollIdle(mVerifyLayout);
    assertEquals(startPos, mGridView.getSelectedPosition());

}

From source file:android.support.v17.leanback.widget.GridWidgetTest.java

public void testNoInitialFocusable() throws Throwable {

    mInstrumentation = getInstrumentation();
    Intent intent = new Intent(mInstrumentation.getContext(), GridActivity.class);
    intent.putExtra(GridActivity.EXTRA_LAYOUT_RESOURCE_ID, R.layout.horizontal_linear);
    final int numItems = 100;
    intent.putExtra(GridActivity.EXTRA_NUM_ITEMS, numItems);
    intent.putExtra(GridActivity.EXTRA_STAGGERED, false);
    mOrientation = BaseGridView.HORIZONTAL;
    mNumRows = 1;//w  ww  .j  a v  a  2  s .c  o  m
    boolean[] focusable = new boolean[numItems];
    final int firstFocusableIndex = 10;
    for (int i = 0; i < firstFocusableIndex; i++) {
        focusable[i] = false;
    }
    for (int i = firstFocusableIndex; i < focusable.length; i++) {
        focusable[i] = true;
    }
    intent.putExtra(GridActivity.EXTRA_ITEMS_FOCUSABLE, focusable);
    initActivity(intent);
    assertTrue(mGridView.isFocused());

    if (mGridView.getLayoutDirection() == ViewGroup.LAYOUT_DIRECTION_RTL) {
        sendKeys(KeyEvent.KEYCODE_DPAD_LEFT);
    } else {
        sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT);
    }
    waitForScrollIdle(mVerifyLayout);
    assertEquals(firstFocusableIndex, mGridView.getSelectedPosition());
    assertTrue(mGridView.getLayoutManager().findViewByPosition(firstFocusableIndex).hasFocus());
}

From source file:im.ene.lab.design.widget.coverflow.FeatureCoverFlow.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_LEFT:
        scroll((int) (-1 * mCoverWidth * mSpacing) - mCenterItemOffset);
        return true;
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        scroll((int) (mCoverWidth * mSpacing) - mCenterItemOffset);
        return true;
    default:/* w  w  w . j a  va  2  s.  co  m*/
        break;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.anysoftkeyboard.AnySoftKeyboard.java

@Override
public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) {
    Logger.d(TAG, "onKeyUp keycode=%d", keyCode);
    switch (keyCode) {
    // Issue 248/*from w  ww.j a  va2s  .  c o m*/
    case KeyEvent.KEYCODE_VOLUME_DOWN:
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (!isInputViewShown()) {
            return super.onKeyUp(keyCode, event);
        }
        if (mAskPrefs.useVolumeKeyForLeftRight()) {
            // no need of vol up/down sound
            return true;
        }
    case KeyEvent.KEYCODE_DPAD_DOWN:
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_DPAD_LEFT:
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (getInputView() != null && getInputView().isShown() && getInputView().isShifted()) {
            event = new KeyEvent(event.getDownTime(), event.getEventTime(), event.getAction(),
                    event.getKeyCode(), event.getRepeatCount(), event.getDeviceId(), event.getScanCode(),
                    KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_ON);
            InputConnection ic = getCurrentInputConnection();
            if (ic != null)
                ic.sendKeyEvent(event);

            return true;
        }
        break;
    case KeyEvent.KEYCODE_ALT_LEFT:
    case KeyEvent.KEYCODE_ALT_RIGHT:
    case KeyEvent.KEYCODE_SHIFT_LEFT:
    case KeyEvent.KEYCODE_SHIFT_RIGHT:
    case KeyEvent.KEYCODE_SYM:
        mMetaState = MyMetaKeyKeyListener.handleKeyUp(mMetaState, keyCode, event);
        Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyUp"));
        setInputConnectionMetaStateAsCurrentMetaKeyKeyListenerState();
        break;
    }
    return super.onKeyUp(keyCode, event);
}

From source file:com.fishstix.dosboxfree.DBGLSurfaceView.java

@Override
public boolean onKeyDown(int keyCode, final KeyEvent event) {
    if (mDebug)//  w w w. j a v a 2s  . co  m
        Log.d("DosBoxTurbo", "onKeyDown keyCode=" + keyCode + " mEnableDpad=" + mEnableDpad);

    if (mEnableDpad) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_UP:
            if ((mInputMode == INPUT_MODE_MOUSE) || (mInputMode == INPUT_MODE_REAL_MOUSE)) {
                y[0] -= mDpadRate;
                DosBoxControl.nativeMouse((int) x[0], (int) y[0], (int) x[0], (int) y[0] + mDpadRate, 2, -1);
                return true;
            } else if ((mInputMode == INPUT_MODE_JOYSTICK) || (mInputMode == INPUT_MODE_REAL_JOYSTICK)) {
                DosBoxControl.nativeJoystick(0, -1024, 2, -1);
                return true;
            }
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if ((mInputMode == INPUT_MODE_MOUSE) || (mInputMode == INPUT_MODE_REAL_MOUSE)) {
                y[0] += mDpadRate;
                DosBoxControl.nativeMouse((int) x[0], (int) y[0], (int) x[0], (int) y[0] - mDpadRate, 2, -1);
                return true;
            } else if ((mInputMode == INPUT_MODE_JOYSTICK) || (mInputMode == INPUT_MODE_REAL_JOYSTICK)) {
                DosBoxControl.nativeJoystick(0, 1024, 2, -1);
                return true;
            }
            break;
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if ((mInputMode == INPUT_MODE_MOUSE) || (mInputMode == INPUT_MODE_REAL_MOUSE)) {
                x[0] -= mDpadRate;
                DosBoxControl.nativeMouse((int) x[0], (int) y[0], (int) x[0] + mDpadRate, (int) y[0], 2, -1);
                return true;
            } else if ((mInputMode == INPUT_MODE_JOYSTICK) || (mInputMode == INPUT_MODE_REAL_JOYSTICK)) {
                DosBoxControl.nativeJoystick(-1024, 0, 2, -1);
                return true;
            }
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if ((mInputMode == INPUT_MODE_MOUSE) || (mInputMode == INPUT_MODE_REAL_MOUSE)) {
                x[0] += mDpadRate;
                DosBoxControl.nativeMouse((int) x[0], (int) y[0], (int) x[0] - mDpadRate, (int) y[0], 2, -1);
                return true;
            } else if ((mInputMode == INPUT_MODE_JOYSTICK) || (mInputMode == INPUT_MODE_REAL_JOYSTICK)) {
                DosBoxControl.nativeJoystick(1024, 0, 2, -1);
                return true;
            }
            break;
        case KeyEvent.KEYCODE_DPAD_CENTER: // button
            if ((mInputMode == INPUT_MODE_MOUSE) || (mInputMode == INPUT_MODE_REAL_MOUSE)) {
                DosBoxControl.nativeMouse(0, 0, 0, 0, 0, BTN_A);
                return true;
            } else if ((mInputMode == INPUT_MODE_JOYSTICK) || (mInputMode == INPUT_MODE_REAL_JOYSTICK)) {
                DosBoxControl.nativeJoystick(0, 0, 0, BTN_A);
                return true;
            }
            break;
        }
    }
    return handleKey(keyCode, event);
}

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

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK:
        if (event.getRepeatCount() == 0 && mKeyboardSwitcher.getInputView() != null) {
            if (mKeyboardSwitcher.getInputView().handleBack()) {
                return true;
            } else if (mTutorial != null) {
                mTutorial.close();// w  w w.  j  a v  a2 s  .c  om
                mTutorial = null;
            }
        }
        break;
    case KeyEvent.KEYCODE_DPAD_DOWN:
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_DPAD_LEFT:
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        // If tutorial is visible, don't allow dpad to work
        if (mTutorial != null) {
            return true;
        }
        break;
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (!mVolUpAction.equals("none") && isKeyboardVisible()) {
            return true;
        }
        break;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (!mVolDownAction.equals("none") && isKeyboardVisible()) {
            return true;
        }
        break;
    }
    return super.onKeyDown(keyCode, event);
}