1

I need to get some information from the on screen keyboard such as pressure, KeyDown and KeyUp in Android but don't know how to do that.

The android official site says that:

Note: 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).

I also tried the following method without success. It actually works with the hardware keys like back button.

myEditText.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View view, int i, KeyEvent keyEvent) {
            return false;
        }
    });

I was thinking of finding a way of extending the on screen keyboard, but still no success! Does anyone have ever tried doing this? I'd appreciate your help in advance.

UPDATE: After trying many solutions I came up with the same solution of using my own keyboard, suggested by krossovochkin, ultimately. It seems that the solution is not too bad if one wants to modify the Android's keyboard as a new one. This way, it appears in the "Settings --> Input Methods" so that the user can switch to the new keyboard, which is good since it is accessible from all other apps. Since it is not yet clear that whether it is possible to get the pressure from the standard virtual keyboard, therefore I thought the question could be left open.

Eb Abadi
  • 585
  • 5
  • 17
  • So your question is "_Has anyone ever tried to extend the soft keyboard of android?_" – takendarkk Apr 18 '14 at 06:51
  • For finding pressure, the answer is already shared here http://stackoverflow.com/questions/9312518/android-find-pressure-on-screen/9312570#9312570 – Vishnuraj V Apr 18 '14 at 06:52
  • @Takendarkk Yes, but mainly for this purpose, which is capturing its key events. Please let me know if you know a sample code that did that. Thanks. – Eb Abadi Apr 18 '14 at 14:48
  • @vishnurajv Yes, I've seen that, it actually works pretty fine with the views or widgets like button, but I couldn't get the pressure from the virtual keyboard. – Eb Abadi Apr 18 '14 at 14:50

1 Answers1

1

You can try to call getPressure() method from MotionEvent Link: http://developer.android.com/reference/android/view/MotionEvent.html#getPressure%28int%29

Code snippet:

view.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        float pressure = event.getPressure();
    }
});

UPDATE: You can create your own keyboard and getPressure from it. Maybe user will not like using your keyboard instead of his default keyboard. But I think this is the best solution for your situation.

More information about:
KeyboardView: http://developer.android.com/reference/android/inputmethodservice/KeyboardView.html
Example of creating your own keyboard: https://github.com/rciovati/Android-KeyboardView-Example

krossovochkin
  • 12,030
  • 7
  • 31
  • 54
  • Thanks. That's right, but my question is that how you would get the pressure from the virtual keyboard. – Eb Abadi Apr 18 '14 at 14:51