How do I get the keyCode?

I want to make a KeyHandler class to make it so I can press multiple keys, but I don’t know how to get the ASCII integer value for every key, how do I do this?

Why do you need the ascii code? What are some example keys that you’re trying to use?

I need to get if any key on the keyboard is pressed.

I’m not sure I understand what you’re asking- doesn’t the keyCode variable already give you that?

It only gives coded keys like shift, control, ect.

Have you tested that theory? The keyCode variable prints out ascii values for all of the keys on my keyboard.

Yup. I have. Every other key prints out 0.

This is also for that 3D engine!

Hmm, interesting. The keyCode works fine for me on Windows. Maybe it’s a platform-specific thing.

The key variable contains the character that was typed. You can probably just cast to int to get the ascii code:

println( (int) key );

I’ll try that, but, I AM using Windows! Hmmm…

Try this sketch:

void draw(){}

void keyPressed(){
 println("key: " + key);
 println("int key: " + (int) key);
 println("keyCode: " + keyCode);

For me, this prints out reasonable values for every key on my keyboard.

1 Like

It works! Thanks a lot!!

1 Like

@GoToLoop Can you please include an explanation when you post links?

1 Like

Haha plus 1 from me for that post