0
votes

I am developing an android application (keyboard driver) in which first I am connecting Bluetooth keyboard with android device , after successful connection in my Inputmethod service I am receiving key presses and send it to currently open editor. The problem is that I am unable to figure out how to turn on/off caps lock and shift key functionality in android.

    private BroadcastReceiver key3Receiver = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {
        int key = Integer.parseInt(intent
                .getStringExtra(BluezService.COLONY_KEYPRESS_KEY));
        int action = intent.getIntExtra(BluezService.EVENT_KEYPRESS_ACTION,
                KeyEvent.ACTION_DOWN);
        Log.d("++++ key recieved   ", Integer.toString(key));

        InputConnection ic = getCurrentInputConnection();
        long eventTime = SystemClock.uptimeMillis();

        if(key==2)
        {
            if(checkEnable==true){
                ic.clearMetaKeyStates(KeyEvent.META_SHIFT_LEFT_ON);
                Log.d("metakey", "turn off");
                checkEnable=false;
                return;
            }else{
                Log.d("metakey", "turn on");
                checkEnable=true;
            }
        }
        // ********* Hacks
        if(key==8)
        {
            key=127;
        }



        if (key < 130) {

            ic.sendKeyEvent(new KeyEvent(eventTime, eventTime, action,COLONYKEYCODE[key],
                    0, KeyEvent.META_SHIFT_ON, 0, 0, KeyEvent.FLAG_SOFT_KEYBOARD));
        }

    }
};
1
Kindly don't repeat the questions you have already posted. stackoverflow.com/questions/10794848/…Kazekage Gaara

1 Answers

2
votes

I found the solution it may help someone. What i was doing wrong , I call KeyEvent.ACTION_DOWN and forget to call KeyEvent.ACTION_UP for action in ic.sendKeyEvent(...) , that is why it was not releasing shift key.