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

**URL:** <https://discourse.processing.org/t/java-keypressed-function-cant-i-get-korean-japanese-chinese-etc/38799>\
**Category:** Coding Questions\
**Created:** [September 16, 2022, 8:25am UTC](https://discourse.processing.org/t/java-keypressed-function-cant-i-get-korean-japanese-chinese-etc/38799 "2022-09-16T08:25:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [September 16, 2022, 8:25am UTC](https://discourse.processing.org/t/java-keypressed-function-cant-i-get-korean-japanese-chinese-etc/38799/1 "2022-09-16T08:25:37Z")

</div>

[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?

```auto
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);
}

```

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [September 16, 2022, 12:11pm UTC](https://discourse.processing.org/t/java-keypressed-function-cant-i-get-korean-japanese-chinese-etc/38799/2 "2022-09-16T12:11:18Z")

</div>

Hi @GWAK,

I suppose that Korean/Japanese/Chinese characters are not part of the ASCII specification (see: [unicode - Japanese ASCII Code - Stack Overflow](https://stackoverflow.com/a/1801554)).

And the [`keyCode`](https://processing.org/reference/keyCode.html) 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 😉 )

---

<div class="post-metadata">

**Author:** ![NumericPrime](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/numericprime/32/16318_2.png) [@NumericPrime](https://discourse.processing.org/u/NumericPrime)\
**Post date:** [September 16, 2022, 2:42pm UTC](https://discourse.processing.org/t/java-keypressed-function-cant-i-get-korean-japanese-chinese-etc/38799/3 "2022-09-16T14:42:01Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [September 17, 2022, 1:08am UTC](https://discourse.processing.org/t/java-keypressed-function-cant-i-get-korean-japanese-chinese-etc/38799/4 "2022-09-17T01:08:06Z")

</div>

@josephh

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

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

```

 ![a1](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/4/8/48e4b0f9a83e3ad4803b608be326eb3c14ef2775.jpeg)

There is no input on the keyboard.

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [September 17, 2022, 1:12am UTC](https://discourse.processing.org/t/java-keypressed-function-cant-i-get-korean-japanese-chinese-etc/38799/5 "2022-09-17T01:12:29Z")

</div>

@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](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/c/c/cc348b7087ced74b35df6471d786dcf74b1b577e.jpeg)

---

<div class="post-metadata">

**Author:** ![NumericPrime](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/numericprime/32/16318_2.png) [@NumericPrime](https://discourse.processing.org/u/NumericPrime)\
**Post date:** [September 17, 2022, 6:56am UTC](https://discourse.processing.org/t/java-keypressed-function-cant-i-get-korean-japanese-chinese-etc/38799/6 "2022-09-17T06:56:50Z")

</div>

@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:

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

```

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

> [@GWAK](#):
>
> scancode=56

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:

```auto
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);

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [September 17, 2022, 4:46pm UTC](https://discourse.processing.org/t/java-keypressed-function-cant-i-get-korean-japanese-chinese-etc/38799/7 "2022-09-17T16:46:11Z")

</div>

> **[Reference](https://processing.org/reference/keyTyped_.html)**
>
> The keyTyped() function is called once every time a key is pressed, but action keys such as Ctrl, Shift, and Alt are ignored. Because of how operating systems handle key repeats, …

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [September 19, 2022, 10:56pm UTC](https://discourse.processing.org/t/java-keypressed-function-cant-i-get-korean-japanese-chinese-etc/38799/8 "2022-09-19T22:56:08Z")

</div>

@NumericPrime

Thanks for your kind reply.

@GoToLoop

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