2

I would like to know if it is possible to listen out for key presses on the android keyboard. So when a letter is pressed then I can update a TextView when the key is released in realtime. I want to be able to show the word in reverse so to store each character in an array the append this back in reverse for the textView.

So can it be done, to set and onKeyListener maybe for the keyboard? or another way?

1 Answer 1

2

"to listen out for key press on the android keyboard"

You may use the following code snippets:

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) // KeyEvent.* lists all the key codes u pressed
        {   // do something on back.
        }  
        return super.dispatchKeyEvent(event);
    }

Or

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)  {
        if (keyCode == KeyEvent.KEYCODE_BACK) { // KeyEvent.* lists all the key codes u pressed
             // do something on back.
        }
        return super.onKeyDown(keyCode, event);
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Your first answer worked perfectly thanks don't need to try these ones.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.