Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get caps lock state in Android

How can I get the caps lock state in Android using a hardware keyboard? In pure Java it can be detected with

boolean isOn = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);

But this does not work with Android...

like image 331
Kewitschka Avatar asked Mar 02 '16 10:03

Kewitschka


1 Answers

Try This (didn't test it):

public class CustomEditText extends EditText{


public CustomEditText(Context context) {
    super(context);
}

public CustomEditText(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public CustomEditText(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(event.isCapsLockOn()){
        //Do what Ever
    }
    return super.onKeyDown(keyCode, event);
}

}

isCapsLockOn

like image 71
royB Avatar answered Sep 19 '22 12:09

royB