[JAVA] Keypressed function / Can't I get Korean, Japanese, Chinese, etc.?

[JAVA] Keypressed function / Can’t I get Korean, Japanese, Chinese, etc.?

  1. You cannot receive data through Keypressed.

  2. Is it correct that it cannot be received with the ‘Key’ function in processing? Or is there another way?

void setup() {
 size(500,500);
 textSize(100); textAlign(CENTER,CENTER); fill(0); 
}
void draw() {
 background(255);
 text(strs,250,250);
}
String strs = "";
void keyPressed() {
  println(" key : " + str(key));
  strs=str(key);
}

Hi @GWAK,

I suppose that Korean/Japanese/Chinese characters are not part of the ASCII specification (see: unicode - Japanese ASCII Code - Stack Overflow).

And the keyCode specification says this:

The keys included in the ASCII specification (BACKSPACE, TAB, ENTER, RETURN, ESC, and DELETE) do not require checking to see if the key is coded; for those keys, you should simply use the key variable directly (and not keyCode).

→ So try using keyCode and you should be able to get non ASCII characters (someone correct me if I’m wrong :wink: )

1 Like

If using plain keyCode doesn’t work either try running this sketch:

import javax.swing.*;

JFrame jf=new JFrame();
jf.setSize(600, 600);
jf.addKeyListener(new java.awt.event.KeyListener() {
  @Override
  public void keyReleased(java.awt.event.KeyEvent e) {
    println("KeyCode: "+e.getKeyCode()+"\nExtended KeyCode: "+ e.getExtendedKeyCode()+"\nParameters: "+e.paramString()+"\nChar: "+e.getKeyChar());
  }
  @Override
  public void keyTyped(java.awt.event.KeyEvent e) {
  }
  @Override
  public void keyPressed(java.awt.event.KeyEvent e) {
  }
}
);
//Replaced c with the char you want to detect
println("Searched "+java.awt.event.KeyEvent.getExtendedKeyCodeForChar('c'));
jf.setVisible(true);

And press the key you want to detect and a unrelated one and post the contents of the console.

This would be an example output with the German ‘ü’

Searched 16777468
KeyCode: 0
Extended KeyCode: 16777468
Parameters: KEY_RELEASED,keyCode=0,keyText=Unbekannt keyCode: 0x0,keyChar=‘ü’,keyLocation=KEY_LOCATION_STANDARD,rawCode=186,primaryLevelUnicode=252,scancode=26,extendedKeyCode=0x10000fc
Char: ü

As we see here ü and in fact all of the Umlaute have a KeyCode of 0. So your best bet might actually be to use the extended keyCode here.

@GWAK if the sketch posted gives you an Extended KeyCode !=0 I can post some code that tracks keys based on the Extended KeyCode otherwise it won’t be useful.

2 Likes

@josephh

thank you for the reply. Even ‘keyCode’ is not resolved.

void keyPressed() {
  println(" key : " + str(keyCode));
  strs=str(keyCode);
}

There is no input on the keyboard.

@NumericPrime

thank you.

Parameters: KEY_RELEASED,keyCode=0,keyText=알 수 없음 keyCode: 0x0,keyChar=정의되지 않음 keyChar,keyLocation=KEY_LOCATION_STANDARD,rawCode=21,primaryLevelUnicode=0,scancode=56,extendedKeyCode=0x0

I can’t seem to define it.
And no matter how much foreign language is entered, only English in the same place is entered.
(same place on the keyboard)

a2

@GWAK

I have another Idea you can try. From the data that you sent me it seems the key picks up something as char. Try the following:

void setup(){
  size(100,100);
}
void draw(){
}
void keyPressed(){
println((int) key);
}

If this only gives you garbage there is a last resort solution.:

This is one of a few of the parameters that it isn’t 0 this is because it doesn’t care for the mapping of the keyBoard.

I don’t know if Korean keyboards also have shift,alt and crtl if so you should have no problem using modifiers.

You can use a variation of the last sketch to find out the scancode:

import javax.swing.*;

JFrame jf=new JFrame();
jf.setSize(600, 600);
jf.addKeyListener(new java.awt.event.KeyListener() {
  @Override
    public void keyReleased(java.awt.event.KeyEvent e) {
    println("\nParameters: "+e.paramString()+"\nModifiers:"+e.getModifiers());
  }
  @Override
    public void keyTyped(java.awt.event.KeyEvent e) {
  }
  @Override
    public void keyPressed(java.awt.event.KeyEvent e) {
  }
}
);
jf.setVisible(true);

2 Likes
2 Likes

@NumericPrime

Thanks for your kind reply.

@GoToLoop

Thank you for answer.
I didn’t know there was a function. thank you