Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to listen the keypress in the soft keyboard?

I need a listener to identify the keypress in the soft keyboard/on screen keyboard.

I tried with addtextchangelistener textwatcher but this one give the good result but it shows the change also when some text is pasted into it.

I need to identify only the key press by the user.

Is there any possible way to detect the key press.

like image 899
arnp Avatar asked May 16 '12 10:05

arnp


2 Answers

see this keyevent and use following code to identify which key is pressed by Users.

  @Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) 
    {
         // Do Code here
    }
else if(keyCode == KeyEvent.KEYCODE_0) 
   {

   }
else if(keyCode == KeyEvent.KEYCODE_1) 
   {

   }
return super.onKeyDown(keyCode, event); }
like image 112
Ronak Mehta Avatar answered Nov 05 '22 14:11

Ronak Mehta


When handling keyboard events with the KeyEvent class and related APIs, you should expect that such keyboard events come only from a hardware keyboard. You should never rely on receiving key events for any key on a soft input method (an on-screen keyboard).

see: Handling Keyboard Actions

like image 38
phnmnn Avatar answered Nov 05 '22 16:11

phnmnn