1

I am working on Customized Keyboard, I should operate the Pc using Android Keyboard, So For that I have implemented a keyboard. there is no edit text/text view in my activity to show keyboard. I am displaying the keyboard on button clicks. Now I am unable to Detect the Modifer keys such as Ctrl/Alt are pressed . I have Implemented Keyboard Action listener but there is no method for handling the Combination of keys like KeyDown/KeyUp Here is My listener , Please check suggest.

    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() {
    }

};

This is Code for displaying Custom keyboard in activity .

mKeyboardView = (KeyboardView) findViewById(R.id.keyboardview);
    mKeyboardView.setOnKeyboardActionListener(mOnKeyboardActionListener);
    mKeyboardView.setKeyboard(new Keyboard(
            MainActivity.this, R.xml.qwerty));
    mKeyboardView.setPreviewEnabled(true); 
Roster
  • 1,764
  • 6
  • 17
  • 36

0 Answers0