KEYCODE_SHIFT_LEFT源码实例Demo

android.view.KeyEvent#KEYCODE_SHIFT_LEFT源码实例Demo

下面列出了android.view.KeyEvent#KEYCODE_SHIFT_LEFT 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。


/**
 * Handles presses of the meta keys.
 */
public boolean onKeyDown(View view, Editable content, int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_SHIFT_LEFT || keyCode == KeyEvent.KEYCODE_SHIFT_RIGHT) {
        press(content, CAP);
        return true;
    }

    if (keyCode == KeyEvent.KEYCODE_ALT_LEFT || keyCode == KeyEvent.KEYCODE_ALT_RIGHT
            || keyCode == KeyEvent.KEYCODE_NUM) {
        press(content, ALT);
        return true;
    }

    if (keyCode == KeyEvent.KEYCODE_SYM) {
        press(content, SYM);
        return true;
    }

    return false; // no super to call through to
}
 

/**
 * Handles release of the meta keys.
 */
public boolean onKeyUp(View view, Editable content, int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_SHIFT_LEFT || keyCode == KeyEvent.KEYCODE_SHIFT_RIGHT) {
        release(content, CAP, event);
        return true;
    }

    if (keyCode == KeyEvent.KEYCODE_ALT_LEFT || keyCode == KeyEvent.KEYCODE_ALT_RIGHT
            || keyCode == KeyEvent.KEYCODE_NUM) {
        release(content, ALT, event);
        return true;
    }

    if (keyCode == KeyEvent.KEYCODE_SYM) {
        release(content, SYM, event);
        return true;
    }

    return false; // no super to call through to
}
 

/**
 * Handles presses of the meta keys.
 */
public static long handleKeyDown(long state, int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_SHIFT_LEFT || keyCode == KeyEvent.KEYCODE_SHIFT_RIGHT) {
        return press(state, META_SHIFT_ON, META_SHIFT_MASK,
                META_CAP_LOCKED, META_CAP_PRESSED, META_CAP_RELEASED, META_CAP_USED);
    }

    if (keyCode == KeyEvent.KEYCODE_ALT_LEFT || keyCode == KeyEvent.KEYCODE_ALT_RIGHT
            || keyCode == KeyEvent.KEYCODE_NUM) {
        return press(state, META_ALT_ON, META_ALT_MASK,
                META_ALT_LOCKED, META_ALT_PRESSED, META_ALT_RELEASED, META_ALT_USED);
    }

    if (keyCode == KeyEvent.KEYCODE_SYM) {
        return press(state, META_SYM_ON, META_SYM_MASK,
                META_SYM_LOCKED, META_SYM_PRESSED, META_SYM_RELEASED, META_SYM_USED);
    }
    return state;
}
 

/**
 * Handles release of the meta keys.
 */
public static long handleKeyUp(long state, int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_SHIFT_LEFT || keyCode == KeyEvent.KEYCODE_SHIFT_RIGHT) {
        return release(state, META_SHIFT_ON, META_SHIFT_MASK,
                META_CAP_PRESSED, META_CAP_RELEASED, META_CAP_USED, event);
    }

    if (keyCode == KeyEvent.KEYCODE_ALT_LEFT || keyCode == KeyEvent.KEYCODE_ALT_RIGHT
            || keyCode == KeyEvent.KEYCODE_NUM) {
        return release(state, META_ALT_ON, META_ALT_MASK,
                META_ALT_PRESSED, META_ALT_RELEASED, META_ALT_USED, event);
    }

    if (keyCode == KeyEvent.KEYCODE_SYM) {
        return release(state, META_SYM_ON, META_SYM_MASK,
                META_SYM_PRESSED, META_SYM_RELEASED, META_SYM_USED, event);
    }
    return state;
}
 
源代码5 项目: talkback   文件: KeyComboModelApp.java

@Override
public boolean isEligibleKeyComboCode(long keyComboCode) {
  if (keyComboCode == KEY_COMBO_CODE_UNASSIGNED) {
    return true;
  }

  int modifier = KeyComboManager.getModifier(keyComboCode);
  if ((modifier & REQUIRED_MODIFIER_MASK) == 0
      || (modifier | ELIGIBLE_MODIFIER_MASK) != ELIGIBLE_MODIFIER_MASK) {
    return false;
  }

  int keyCode = KeyComboManager.getKeyCode(keyComboCode);
  return keyCode != 0
      && keyCode != KeyEvent.KEYCODE_SHIFT_LEFT
      && keyCode != KeyEvent.KEYCODE_SHIFT_RIGHT
      && keyCode != KeyEvent.KEYCODE_ALT_LEFT
      && keyCode != KeyEvent.KEYCODE_ALT_RIGHT
      && keyCode != KeyEvent.KEYCODE_CTRL_LEFT
      && keyCode != KeyEvent.KEYCODE_CTRL_RIGHT;
}
 

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
	if (event.getAction() == KeyEvent.ACTION_DOWN)
		return false;
	if (keyCode == KeyEvent.KEYCODE_ALT_LEFT
			|| keyCode == KeyEvent.KEYCODE_ALT_RIGHT
			|| keyCode == KeyEvent.KEYCODE_SHIFT_LEFT
			|| keyCode == KeyEvent.KEYCODE_SHIFT_RIGHT)
		return false;

	if (keyCode == KeyEvent.KEYCODE_DEL
			&& this.getText().toString().length() == 0) {
		if (delegate != null) {
			delegate.focusOnPreviousField(this);
		}
	}
	return false;
}
 

private void cancelSelect() {
    if (getCurrentIC() == null) {
        return;
    }
    KeyEvent event = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT);
    sendKeyEvent(event);
    mStatus = Status.direct;
    updateSelector();

}
 

private void beginSelect() {
    if (getCurrentIC() == null) {
        return;
    }
    recordSelect();
    if (mStatus != Status.select) {
        cancelSelectWithSelection();
        return;
    }

    KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT);
    sendKeyEvent(event);
}
 

@Override
public boolean sendKeyEvent(KeyEvent event) {
    switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_SHIFT_LEFT:
            if (isSelectText())
                selectText(false);
            else
                selectText(true);
            break;
        case KeyEvent.KEYCODE_DPAD_LEFT:
            moveCaretLeft();
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            moveCaretUp();
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            moveCaretRight();
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            moveCaretDown();
            break;
        case KeyEvent.KEYCODE_MOVE_HOME:
            moveCaret(0);
            break;
        case KeyEvent.KEYCODE_MOVE_END:
            moveCaret(_hDoc.length());
            break;
        default:
            return super.sendKeyEvent(event);
    }
    return true;
}
 
源代码10 项目: CodeEditor   文件: FreeScrollingTextField.java

@Override
public boolean sendKeyEvent(KeyEvent event) {
    switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_SHIFT_LEFT:
            if (isSelectText())
                selectText(false);
            else
                selectText(true);
            break;
        case KeyEvent.KEYCODE_DPAD_LEFT:
            moveCaretLeft();
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            moveCaretUp();
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            moveCaretRight();
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            moveCaretDown();
            break;
        case KeyEvent.KEYCODE_MOVE_HOME:
            moveCaret(0);
            break;
        case KeyEvent.KEYCODE_MOVE_END:
            moveCaret(_hDoc.length());
            break;
        default:
            return super.sendKeyEvent(event);
    }
    return true;
}
 

public boolean sendKeyEvent(KeyEvent event) {
    if(event.getAction()==KeyEvent.ACTION_UP)
        return super.sendKeyEvent(event);
    switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_SHIFT_LEFT:
        case KeyEvent.KEYCODE_SHIFT_RIGHT:
            /*if (isSelectText())
                selectText(false);
            else*/
                selectText(true);
            break;
        case KeyEvent.KEYCODE_DPAD_LEFT:
              _fieldController.moveCaretLeft(true);
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            _fieldController.moveCaretUp(true);
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            _fieldController.moveCaretRight(true);
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            _fieldController.moveCaretDown(true);
            break;
        case KeyEvent.KEYCODE_MOVE_HOME:
            moveCaret(0);
            break;
        case KeyEvent.KEYCODE_MOVE_END:
            moveCaret(_hDoc.length() - 1);
            break;
        default:
            return super.sendKeyEvent(event);
    }
    return true;
}
 

@Override
public boolean sendKeyEvent(KeyEvent event) {
    int keyCode = event.getKeyCode();
    if (keyCode == KeyEvent.KEYCODE_SHIFT_LEFT || keyCode == KeyEvent.KEYCODE_SHIFT_RIGHT) {
        isShiftPressed = event.getAction() == KeyEvent.ACTION_DOWN;
    } else if (keyCode == KeyEvent.KEYCODE_ALT_LEFT || keyCode == KeyEvent.KEYCODE_ALT_RIGHT
            || keyCode == KeyEvent.KEYCODE_NUM) {
        isAltPressed = event.getAction() == KeyEvent.ACTION_DOWN;
    } else if (keyCode == KeyEvent.KEYCODE_SYM) {
        isSymPressed = event.getAction() == KeyEvent.ACTION_DOWN;
    } else if (keyCode == KeyEvent.KEYCODE_CTRL_LEFT || keyCode == KeyEvent.KEYCODE_CTRL_RIGHT) {
        isCtrlPressed = event.getAction() == KeyEvent.ACTION_DOWN;
    }
    return ic.sendKeyEvent(event);
}
 
源代码13 项目: hackerskeyboard   文件: LatinIME.java

private void sendShiftKey(InputConnection ic, boolean isDown) {
    int key = KeyEvent.KEYCODE_SHIFT_LEFT;
    int meta = KeyEvent.META_SHIFT_ON | KeyEvent.META_SHIFT_LEFT_ON;
    if (isDown) {
        sendKeyDown(ic, key, meta);
    } else {
        sendKeyUp(ic, key, meta);
    }
}
 
源代码14 项目: scangon   文件: ScanGunKeyEventHelper.java

private void checkLetterStatus(KeyEvent event) {
    int keyCode = event.getKeyCode();
    if (keyCode == KeyEvent.KEYCODE_SHIFT_RIGHT || keyCode == KeyEvent.KEYCODE_SHIFT_LEFT) {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            //按着shift键,表示大写
            mCaps = true;
        } else {
            //松开shift键,表示小写
            mCaps = false;
        }
    }
}
 
源代码15 项目: kerkee_android   文件: KCWebView.java

private boolean emulateShiftHeldForWebView(View view)
{
    try
    {
        KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);
        shiftPressEvent.dispatch(view, null, null);
        return true;
    }
    catch (Exception e)
    {
        KCLog.e(e);
    }
    return false;
}
 
源代码16 项目: slide-android   文件: CanvasActivity.java

@Override
public boolean onKeyDown(final int keyCode, final KeyEvent event)
{
    if ((keyCode == KeyEvent.KEYCODE_BACK) &&
        (event.getRepeatCount() == 0))
    {
        if (!waiting)
        {
            Toaster.getInstance().showToast("Press back again to close the connection",
                getApplicationContext());

            waiting = true;
            countdown.schedule(
                new TimerTask()
                {
                    @Override
                    public void run()
                    {
                        waiting = false;
                    }
                }, 2000);
        } else
        {
            closeConnection();
        }
        return true;
    } else
    {
        final short[] KEYBOARD = {10000 + 9, 100};
        if (keyCode == KeyEvent.KEYCODE_SHIFT_LEFT
            || keyCode == KeyEvent.KEYCODE_SHIFT_RIGHT)
        {
            AppSettings.getInstance().getConnectionManager().send(KEYBOARD);
        }
    }
    return super.onKeyDown(keyCode, event);
}
 
源代码17 项目: Ansole   文件: TermKeyListener.java

/**
 * Handle a keyUp event.
 *
 * @param keyCode the keyCode of the keyUp event
 */
public void keyUp(int keyCode, KeyEvent event) {
    boolean allowToggle = isEventFromToggleDevice(event);
    switch (keyCode) {
    case KeyEvent.KEYCODE_ALT_LEFT:
    case KeyEvent.KEYCODE_ALT_RIGHT:
        if (allowToggle) {
            mAltKey.onRelease();
            updateCursorMode();
        }
        break;
    case KeyEvent.KEYCODE_SHIFT_LEFT:
    case KeyEvent.KEYCODE_SHIFT_RIGHT:
        if (allowToggle) {
            mCapKey.onRelease();
            updateCursorMode();
        }
        break;

    case KEYCODE_CTRL_LEFT:
    case KEYCODE_CTRL_RIGHT:
        // ignore control keys.
        break;

    default:
        // Ignore other keyUps
        break;
    }
}
 
源代码评论
动弹
沙发等你来抢
 方法所在类
 同类方法