SamRowley
SamRowley

Reputation: 3485

Realtime text input parsing android keyboard

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?

Upvotes: 2

Views: 817

Answers (1)

Vinayak Bevinakatti
Vinayak Bevinakatti

Reputation: 40503

"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);
    }

Upvotes: 2

Related Questions