how do you read android soft keyboard input?
in
Android Processing
•
5 months ago
Hi,
I'm using processing 2.0b6.
With reference to this post (
http://forum.processing.org/topic/show-hide-the-keyboard) I have managed to get the soft keyboard showing in my app but I can't get processing to read the user input typed in the keyboard.
- import android.view.inputmethod.InputMethodManager;
- import android.content.Context;
- boolean key_typed=false;
- boolean keyboard_active=false;
- void setup()
- {
- orientation(LANDSCAPE);
- }
- void draw()
- {
- // background(#FF0000);
- if(keyboard_active) { }
- else { showVirtualKeyboard(); keyboard_active=true; }
- if(key_typed)
- {
- if(key==ENTER||key==RETURN) { println("ENTER/RETURN"); }
- else if(key==BACKSPACE) { println("BACKSPACE"); }
- else { println(key); }
- key_typed=false;
- }
- }
- void keyTyped()
- {
- key_typed=true;
- }
- void showVirtualKeyboard()
- {
- InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
- }
- void hideVirtualKeyboard()
- {
- InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
- }
If I remove all the android stuff, this works in java mode and I can see the keys printed to the console, but when running in android mode, it just ignores all the key inputs.
So is there an android library I need to import in order to get the key inputs and is there an android method I need to call as well?
I checked the wiki but it only talks about how to get CODED inputs.
If by any chance it's not working because I'm using 2.0b6, could anyone specify how I might be able to get the inputs using only android methods?
Finally on a less important note; the keyboard doesn't show if I don't set the orientation. Also if I uncomment line 14 that says background(#FF0000); it doesnt show (Although this works fine a different program :-s).
Any help would be much appreciated as this is the final phase for my app to be app store ready!
Thanks,
Joe.
1