Search code examples
androidkeyboardkeyevent

Android get pressed key on keyboard


I would like get the pressed key on the keyboard, for all edittext etc.. For example I would log the pressed key in my test application.

How can do that ?


Solution

  • use the code:

           editText.addTextChangedListener(new TextWatcher() {
                @Override
                public void onTextChanged(CharSequence s, int start, int before,
                        int count) {
                }
    
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
            }
    
            @Override
            public void afterTextChanged(Editable s) {
                if(s.toString().length() != 0)
                Log.d(""+s.toString().charAt(s.toString().length()-1));