Unable to take input in ControlP5 textbox using VirtualKeyboard

edited July 2014 in Android Mode

I am using controlp5 textbox to take input from the user. I followed "calsign" directions to display and hide virtual keyboard and its working fine (thanks to calsign) but i am not able to take input from that keyboard even if i press its keys. Kindly help plz

Tagged:

Answers

  • Hello khubaib,

    test it code:

         import android.view.inputmethod.InputMethodManager;
     import android.content.Context;
     import android.inputmethodservice.KeyboardView.OnKeyboardActionListener;
     import android.view.KeyEvent;
    byte control_Key = 0;
        void setup()
        {
         showVirtualKeyboard(); 
        }
    
        void draw()
        {
          if (keyPressed == false) 
         {
           control_Key = 0;
         }
              if (keyPressed == true && control_Key == 0) 
         {
           if(key==65535){  control_Key = 1; showVirtualKeyboard();}
           else
           {
           control_Key = 1;
           }
         }
    
    
        background(51);
          int value = key;
            text(key,111,111);
            text(value,111,170);
           delay(888);
        }
    
        void showVirtualKeyboard() 
        {
           key=0;
           control_Key = 1;
           InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
           imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
        }
    

    I know two possible problems:

    You are using keyPressed, it don´t work if you want write key. You're trying to write special characters. key = 655535 and character is lost

    I hope I have been helpful.

    Regards

    Anthony20

  • not working :(

  • but, where's the problem? Does the code gives you a bug? Do you perform a virtual test? or do you load the app into your phone?

    You have tested the application on a mobile device? I can pass you the .apk file if you want.

    I Did a app to load on my phone and it worked.

  • i tested it on my phone and it didnt work. i inserted your code in my app as well but as "showVirtualkeyboard()" is called in draw it keeps loading the keyboard.

  • showVirtualkeyboard() is called when the button to access settings on the phone is pressed.

    it works slow for the delay. Do test delated " delay(888);"

    I'm using the API 10, if not solved by removing the delay, perhaps you have some incompatibility with API.

  • should i make a new project and copy paste your code and run it on my device without any change?

  • Test that, so you can see if the problem is you code or something that escapes us. If your code have a fault, you can put it for review.

  • edited July 2014

    tested your code

        import android.view.inputmethod.InputMethodManager;
        import android.content.Context;
        import android.inputmethodservice.KeyboardView.OnKeyboardActionListener;
        import android.view.KeyEvent;
        byte control_Key = 0;
    
        void setup() {
          showVirtualKeyboard();
        }
    
        void draw() {
          if (keyPressed == false) {
            control_Key = 0;
          }
          if (keyPressed == true && control_Key == 0) {
            if (key==65535) {  
              control_Key = 1; 
              showVirtualKeyboard();
            } else {
              control_Key = 1;
            }
          }
          background(51);
          int value = key;
          text(key, 111, 111);
          text(value, 111, 170);
        }
    
        void showVirtualKeyboard() {
          key=0;
          control_Key = 1;
          InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
          imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
        }
    

    its still not working :(

  • edited July 2014

    Hi, I just gave this a go and short answer is, it is not working properly.

    below is the code I used (to toggle the keyboard, press the square top-left corner; press the textfield to activate it, the box outline will change color)

    The problem for me was that the keyCode mapping for processing java and android are mismatched for some keys (this is not necessarily a processing issue, I did not have a deeper look), hence I get wrong input-character results. Also, the font rendering gives wrong results when exceeding the textfield-box. Both issues don't make controlP5's textfield a viable solution in android mode. What would I do? write a customised text-input suitable for my needs in android mode.

    import android.view.inputmethod.InputMethodManager;
    import android.content.Context;
    import android.inputmethodservice.KeyboardView.OnKeyboardActionListener;
    import android.view.KeyEvent;
    
    import controlP5.*;
    ControlP5 cp5;
    
    void setup() {
    
      cp5 = new ControlP5(this);
    
      cp5.addToggle("keyboard").setPosition(20, 20).setSize(200, 200);
    
      cp5.addTextfield("input")
         .setPosition(20, 300)
         .setSize(200, 40)
         ;
    
      // by default this is not automatically processed in android mode
      registerMethod("keyEvent", cp5); 
    }
    
    void keyboard( boolean a ) {
      showVirtualKeyboard();
    }
    
    void draw() {
      background(20);
      fill(255);
      text((char)key, 300, 100);
      text((int)key+" "+keyCode, 300, 120);
      // just checking, mousepressed is only recognised after ~ half a second touch event
      text(mousePressed ? "PRESS":"-", 300, 220);
    }
    
    
    
    void showVirtualKeyboard() {
      InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    }
    
  • plzzzz anyone with the correct solution? i am stuck at my project plz help :(

  • no answer?

  • @sojamo was pretty clear - you have make your own text box from scratch. There are lots of examples of text boxes out there (including the source code or ControlP5) - it's just a matter of getting one to work with Android and your project...

  • found another library "apWidget" and its text input is working fine on android. But now the problem is that i want to hide and show its individual widgets in different menus. Is there any function of it to hide/lock and show/unlock its individual widgets (textbox, textarea, buttons etc.)?

  • any response?

Sign In or Register to comment.