Android KeyBoardView - 按下检测修改键

时间:2015-10-28 09:30:55

标签: android-softkeyboard android-keypad custom-keyboard

我正在使用自定义键盘,我应该使用Android键盘操作Pc,所以我已经实现了键盘。我的活动中没有编辑文本/文本视图来显示键盘。我在按钮点击时显示键盘。 现在我无法检测按下Ctrl / Alt等Modifer键。 我已经实现了Keyboard Action侦听器,但是没有方法来处理像KeyDown / KeyUp这样的组合键 这是我的倾听者,请检查建议。

    public OnKeyboardActionListener mOnKeyboardActionListener = new OnKeyboardActionListener() {
    public final static int CodeDelete = -5; // Keyboard.KEYCODE_DELETE
    public final static int CodeCancel = -3; // Keyboar d.KEYCODE_CANCEL
    public final static int CodePrev = 55000;
    public final static int CodeAllLeft = 55001;
    public final static int CodeLeft = 55002;
    public final static int CodeRight = 55003;
    public final static int CodeAllRight = 55004;
    public final static int CodeNext = 55005;
    public final static int CodeClear = 55006;

    @Override
    public void onKey(int primaryCode, int[] keyCodes) {
        isAnimate = false;
        Log.e("ON KEY METHOD", "KEY CODE IS " + primaryCode);

        System.out.println("primaryCodeprimaryCode====>>>>>>>>>>"
                + primaryCode);
        switch (primaryCode) {
        case KeyEvent.KEYCODE_A:
            System.out.println("********A PRESSED ******");
            break;
        case KeyEvent.KEYCODE_B:
            System.out.println("********B PRESSED ******");
            break;
        case KeyEvent.KEYCODE_CTRL_LEFT:
            Log.e("Control KEY PREES IN ON KEY", "" + primaryCode);

            System.out.println("********Control KEy PRESSED ******");
            break;
        default:
            break;
        }
    }

    @Override
    public void onPress(int arg0) {
        Log.e("######ON PRESSS", "KEY CODE IS" + arg0);

        System.out.println("on onPress" + arg0);

    }

    @Override
    public void onRelease(int primaryCode) {
        Log.e("*****ON onRelease", "KEY CODE IS " + primaryCode);

        System.out.println("on Release" + primaryCode);

    }

    @Override
    public void onText(CharSequence text) {
        Log.e("*****ON onText", "KEY CODE IS " + text);

        System.out.println("on text" + text);
    }

    @Override
    public void swipeDown() {
    }

    @Override
    public void swipeLeft() {
    }

    @Override
    public void swipeRight() {
    }

    @Override
    public void swipeUp() {
    }

};

这是用于在活动中显示自定义键盘的代码。

mKeyboardView = (KeyboardView) findViewById(R.id.keyboardview);
    mKeyboardView.setOnKeyboardActionListener(mOnKeyboardActionListener);
    mKeyboardView.setKeyboard(new Keyboard(
            MainActivity.this, R.xml.qwerty));
    mKeyboardView.setPreviewEnabled(true); 

0 个答案:

没有答案