User input in non Roman letters

edited March 2014 in Using Processing

I am trying to get user input in Japanese. Here is a Sketch based on Daniel Shiffman example in "Learning Processing: chap 18". I can write Japanese with text(), but cannot convert Japanese characters in the running sketch Windows. Strangely I cannot find this question already asked in the forum!

PFont f;

// Variable to store text currently being typed
String typing = "";

// Variable to store saved text when return is hit
String saved = "";

void setup() {
  size(300,200);
  f = createFont("Hiragino Mincho Pro",16,true);

  //print(PFont.list());
}

void draw() {
  background(255);
  int indent = 25;

  // Set the font and fill for text
  textFont(f);
  fill(0);

  // Display everything
  text("Click in this applet and type. \n 日本語版  return to save what you typed. ", indent, 40);
  text(typing,indent,90);
  text(saved,indent,130);

}

void keyPressed() {
  // If the return key is pressed, save the String and clear it
  if (key == '\n' ) {
    saved = typing;
    // A String can be cleared by setting it equal to ""
    typing = ""; 
  } else {
    // Otherwise, concatenate the String
    // Each character typed by the user is added to the end of the String variable.
    typing = typing + key; 
  }
}

Answers

  • Perhaps you should try keyTyped() instead of keyPressed()? :-??
    I've got an online example which goes w/ that approach:

    http://studio.processingtogether.com/sp/pad/export/ro.9Zo$UbIWYZEDR/latest

  • Thanks for your help, but the result is the same with keyTyped().

    I understand the sketch is able to display Japanese characters, the problem is the way to input and convert keys to Japanese. For example if I switch keyboard mode to direct input I can write with Hiragana; but even here the Kanji conversion is not available. Else in standard keyboard mode (one Hiragana letter is made of two keys combination ex: s+a=さ) the window does not access the Japanese input system and processing raises a Java error in console.

    One bypass solution would be to enable Copy/Paste and paste text written in another software. I have to look if this is possible.

    BTW: my final goal is to interactively generate QRcode

Sign In or Register to comment.