Rahul Gupta
Rahul Gupta

Reputation: 5295

How to find which key is pressed on Android softKeyboard?

Please anyone tell me if there is any listener on finding which key is pressed currently in an EditText from softkeyboard programmatically.

onKeyListener is for hardkeyboard only and i cant write 100 if else conditions for each and every keycode's and using textwatcher you can get the whole string but not the current pressed key. I have looked into all of these solutions.

Note : What i require is that when the user presses "A" key, it should show toast "A" (or any other alphabet)

Upvotes: 1

Views: 1835

Answers (2)

kalyan pvs
kalyan pvs

Reputation: 14590

With using this this listener you will get the current pressed key from keyboard..

@Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        char ch=  s.charAt(start + count - 1); 

    }

here it will print the last entered character..

Upvotes: 1

Eldhose M Babu
Eldhose M Babu

Reputation: 14530

public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
    // Do Code here
}
return super.onKeyDown(keyCode, event);

}

Check this link. It will help you

Upvotes: 0

Related Questions