getUnicodeChar() in android mode?

Hello, I want to get the value of the keypresses with getUnicodeChar()

    import android.view.KeyEvent;
    KeyEvent event;
    int unicodeChar=0;

    void draw()
    {
      if(mousePressed == true){showVirtualKeyboard();delay(888);} 
      unicodeChar = event.getUnicodeChar();
      text(unicodeChar , 22, 22);
      delay(1000);
    }

public void showVirtualKeyboard() { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); }

This code does not work, that I can do?

thanks

Tagged:

Comments

  • @anthony20=== try this

            import android.view.KeyEvent;
            KeyEvent event;
            int unicodeChar;
            import android.content.Context;
            import android.text.InputType;
            import android.view.KeyEvent;
            import android.view.inputmethod.EditorInfo;
            import android.view.inputmethod.InputMethodManager;
            import android.widget.EditText;
            import android.widget.TextView;
            import android.widget.TextView.OnEditorActionListener;
            InputMethodManager imm;
    
            void setup(){
    
            }
    
            void draw()
            {
              if(mousePressed == true){
                showVirtualKeyboard();
    
            } 
    
            }
    
            @Override
                public boolean dispatchKeyEvent(KeyEvent event) {  
                     unicodeChar = event.getUnicodeChar();
                     println(unicodeChar);
                    return super.dispatchKeyEvent(event);
                };
    
            public void showVirtualKeyboard() { 
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); 
    
            };
    
  • --------or (more simple to understand) == (anyway the problem is that in your drawcode the event is always null and so you cannot call event.getUnicodeChar())

        public boolean onKeyUp(int keyCode, KeyEvent event) {
         unicodeChar = event.getUnicodeChar();
              println("unicode" + unicodeChar);
                    return super.onKeyUp(keyCode, event);
            }
    
  • edited February 2015

    Hi, @akenaton Thanks for help me,

    I don´t understand...

    This code work well in tablet and samsung galaxy ace. But in samsung galaxy mini i only can read numeric chars.

    When I press the other characters nothing happens, it is as if the keyboard not connected to event, and the data Char is lost.

  • what running? 2.3................................4.4???

  • same result with my code(try the twos, dispatchevent && onKeyUp())???

  • same result with my code(try the twos, dispatchevent && onKeyUp())??? What returns the println() as for me i have tested on 2 phones and it works...

  • Hi @Akenaton, thanks for the help me,

    I really do not understand why this error happens.

    Anyway, finally I was able to successfully implement the apwidgets library.

    So I'm going to rule out using getUnicodeChar ()

  • yet i am curious to know what returns println()

  • I do it: text(int(unicodeChar),random(800),random(380)); some keys, especially numbers give correct values. However most of letters and other keys are not displayed when pressed, as if these characters were not prosecuted.

    println returns nothing,

    The strange thing is that the code works other devices with apparent normality.

Sign In or Register to comment.