Example usage for android.view KeyEvent getScanCode

List of usage examples for android.view KeyEvent getScanCode

Introduction

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

Prototype

public final int getScanCode() 

Source Link

Document

Retrieve the hardware key id of this key event.

Usage

From source file:com.BibleQuote.BibleQuoteAndroid.ui.ReaderActivity.java

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

    if (keyCode == 0) {
        keyCode = event.getScanCode();
    }//from w  w w  .j  a  v a  2  s.com

    if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP && PreferenceHelper.volumeButtonsToScroll())
            || DevicesKeyCodes.KeyCodeUp(keyCode)) {
        vWeb.pageUp(false);
        viewChapterNav();
        return true;
    } else if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && PreferenceHelper.volumeButtonsToScroll())
            || DevicesKeyCodes.KeyCodeDown(keyCode)) {
        vWeb.pageDown(false);
        viewChapterNav();
        return true;
    } else {
        return super.onKeyDown(keyCode, event);
    }
}

From source file:com.vladstirbu.cordova.Gamepad.java

/**
 * @param cordova The context of the main Activity.
 * @param webView The associated CordovaWebView.
 */// w  w w.j a  va  2s .c o  m
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    this.map.put("KEYCODE_BUTTON_A", 0);
    this.map.put("KEYCODE_BUTTON_B", 1);
    this.map.put("KEYCODE_BUTTON_Y", 3);
    this.map.put("KEYCODE_BUTTON_X", 2);
    this.map.put("KEYCODE_BUTTON_L1", 4);
    this.map.put("KEYCODE_BUTTON_R1", 5);
    this.map.put("KEYCODE_BUTTON_L2", 6);
    this.map.put("KEYCODE_BUTTON_R2", 7);
    this.map.put("KEYCODE_SPACE", 8);
    this.map.put("KEYCODE_SELECT", 8);
    this.map.put("KEYCODE_ENTER", 9);
    this.map.put("KEYCODE_START", 9);
    this.map.put("KEYCODE_BUTTON_THUMBL", 10);
    this.map.put("KEYCODE_BUTTON_THUMBR", 11);
    this.map.put("KEYCODE_DPAD_UP", 12);
    this.map.put("KEYCODE_DPAD_DOWN", 13);
    this.map.put("KEYCODE_DPAD_LEFT", 14);
    this.map.put("KEYCODE_DPAD_RIGHT", 15);
    this.map.put("KEYCODE_BACK", 16);
    this.map.put("KEYCODE_BUTTON_MODE", 16);

    this.webView.setFocusable(true);
    this.webView.setFocusableInTouchMode(true);
    this.webView.requestFocus();

    this.webView.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            //Log.v("Keyboards", String.valueOf(InputDevice.getDeviceIds().length));
            //Log.v("Input", InputDevice.getDevice(1).getName());
            //Log.v("Input", String.valueOf(InputDevice.getDevice(1).getSources()));

            //Log.v("Device id", String.valueOf(event.getDeviceId()));
            //Log.v("Source id", String.valueOf(event.getSource()));
            //Log.v("Input device", String.valueOf(InputDevice.getDevice(event.getDeviceId()).getName()));
            Log.v("KEY", String.valueOf(event.getScanCode()));
            Log.v("KEY", KeyEvent.keyCodeToString(keyCode));
            //Log.v("GamePad", String.valueOf(KeyEvent.isGamepadButton(keyCode)));

            String jsStr = jsString(keyCode, event);
            if (!jsStr.isEmpty()) {
                self.webView.sendJavascript(jsStr);
            }
            return true;
        }
    });
    this.webView.setOnGenericMotionListener(new OnGenericMotionListener() {
        public boolean onGenericMotion(View v, MotionEvent event) {
            if (event.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK)) {
                if (event.getAction() == MotionEvent.ACTION_MOVE) {
                    // process the joystick movement...
                    JSONObject data = new JSONObject();
                    JSONArray axes = new JSONArray();
                    try {
                        axes.put(event.getAxisValue(MotionEvent.AXIS_X));
                        axes.put(event.getAxisValue(MotionEvent.AXIS_Y));
                        axes.put(event.getAxisValue(MotionEvent.AXIS_Z));
                        axes.put(event.getAxisValue(MotionEvent.AXIS_RZ));
                        data.put("deviceId", event.getDeviceId());
                        data.put("axes", axes);
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    self.webView.sendJavascript(
                            "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");");

                    data = new JSONObject();
                    try {
                        data.put("deviceId", event.getDeviceId());
                        data.put("button", 6);
                        data.put("value", event.getAxisValue(MotionEvent.AXIS_LTRIGGER));
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    self.webView.sendJavascript(
                            "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");");

                    data = new JSONObject();
                    try {
                        data.put("deviceId", event.getDeviceId());
                        data.put("button", 7);
                        data.put("value", event.getAxisValue(MotionEvent.AXIS_RTRIGGER));
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    self.webView.sendJavascript(
                            "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");");

                    float hatX = event.getAxisValue(MotionEvent.AXIS_HAT_X);
                    float hatY = event.getAxisValue(MotionEvent.AXIS_HAT_Y);
                    try {
                        data = new JSONObject();
                        data.put("deviceId", event.getDeviceId());
                        data.put("button", 14);
                        data.put("value", hatX < 0.0f);
                        self.webView.sendJavascript(
                                "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");");
                        data = new JSONObject();
                        data.put("deviceId", event.getDeviceId());
                        data.put("button", 15);
                        data.put("value", hatX > 0.0f);
                        self.webView.sendJavascript(
                                "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");");
                    } catch (JSONException e) {
                    }
                    try {
                        data = new JSONObject();
                        data.put("deviceId", event.getDeviceId());
                        data.put("button", 12);
                        data.put("value", hatY < 0.0f);
                        self.webView.sendJavascript(
                                "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");");
                        data = new JSONObject();
                        data.put("deviceId", event.getDeviceId());
                        data.put("button", 13);
                        data.put("value", hatY > 0.0f);
                        self.webView.sendJavascript(
                                "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");");
                    } catch (JSONException e) {
                    }
                }
                Log.v("MOTION", event.toString());
                return true;
            }
            return false;
        }
    });

    Log.v("GamepadButtons", "initialized");
}

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  w  w. ja  va  2 s. co 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:org.pocketworkstation.pckeyboard.LatinIME.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_DOWN:
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_DPAD_LEFT:
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
        // Enable shift key and DPAD to do selections
        if (inputView != null && inputView.isShown() && inputView.getShiftState() == Keyboard.SHIFT_ON) {
            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);// w  w w.  ja v a  2  s .com
            return true;
        }
        break;
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (!mVolUpAction.equals("none") && isKeyboardVisible()) {
            return doSwipeAction(mVolUpAction);
        }
        break;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (!mVolDownAction.equals("none") && isKeyboardVisible()) {
            return doSwipeAction(mVolDownAction);
        }
        break;
    }
    return super.onKeyUp(keyCode, event);
}

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

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    switch (keyCode) {
    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;
        }/*from w ww.  ja  v  a 2s.  co  m*/
        TKKeyboardView inputView = mKeyboardSwitcher.getInputView();
        // Enable shift key and DPAD to do selections
        if (inputView != null && inputView.isShown() && inputView.getShiftState() == Keyboard.SHIFT_ON) {
            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_VOLUME_UP:
        if (!mVolUpAction.equals("none") && isKeyboardVisible()) {
            return doSwipeAction(mVolUpAction);
        }
        break;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (!mVolDownAction.equals("none") && isKeyboardVisible()) {
            return doSwipeAction(mVolDownAction);
        }
        break;
    }
    return super.onKeyUp(keyCode, event);
}

From source file:com.tct.mail.ui.AbstractActivityController.java

@Override
public final boolean onKeyDown(int keyCode, KeyEvent event) {
    //[FRETURE]-ADD-BEGIN by TSNJ.wei huang 11/24/2014 FR848855
    if (keyCode == event.KEYCODE_BACK) {
        if (mCabActionMenu != null) {
            if (mCabActionMenu.isActivated()) {
                if (mCabActionMenu.isActionModeNull()) {
                    return false;
                } else {
                    mCabActionMenu.onSetEmpty();
                }/*from   w  ww  .j av a  2s  .  com*/
                return true;
            } else {
                return false;
            }
        }
    }
    //[FEATURE]-ADD-END by TSNJ.wei huang

    // TS: gangjin.weng 2015-4-5 EMAIL BUGFIX-968391 ADD_S
    if (keyCode == KeyEvent.KEYCODE_DEL && mCabActionMenu == null && event != null && event.getScanCode() == 0
            && event.getMetaState() == 0
            && event.getFlags() == (KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE)) {
        return true;
    }
    // TS: gangjin.weng 2015-4-5 EMAIL BUGFIX-968391 ADD_E
    return false;
}