Sketch 84552 don't work, error

here where download the sketch:

Hi, I have just entered the world of processing and I am really a beginner, I have only a little understood how to use processing sketches by trial and error.
I’m trying to run the sketch 84522 but I get the error: if (keyCode == KeyEvent.VK_1)

I copied all the .pde files in the same folder and I inserted a .jpeg image inside the sketch folder (inside data) giving it the name shown in the script (delorien)
but it doesn’t work … do you have any suggestions?

1 Like

better use in PDE

https://processing.org/reference/key.html

if ( key == '1' ) {}  // key [1] pressed

also it is not impossible, stay away from combination [ctrl][1] [alt][1] [shift]…
add it makes sense to echo

println( key , keyCode );
1 Like

so sorry,but i can’t understand what i must do
(i’m using processing 2 because i need this version for polargraph)…
---- i must insert println( key , keyCode ); to echo? i don’t know what is echo!!

processing PDE / JAVA mode /
println();
print to the console, so you can better follow / diagnose your code
i suggested to put that line into your
void keyPressed() {}
and you could have just tried??
please run

void setup(){}
void draw(){}
void keyPressed(){
  println(key, keyCode); 
}

as a very beginner why not play with reference / examples,
( from that PDE version you use 2.2.1)

a back convert from old processing.js code is a heavy way of learning.

1 Like

VK_0 thru VK_9 are the same as ASCII ‘0’ thru ‘9’

so, as @kll suggested:

if ( key == '1' )

1 Like

Question : what about import awt.*;

Wouldn’t that import all the VK_ constants?

1 Like

I think that importing java.awt.event.KeyEvent might be a bad idea because a different version of KeyEvent is already built into Processing.

For characters, just check the char against key. For special characters, use keyCode as described in the reference –

This is the same in the Processing 2 and Processing 3 reference.

2 Likes

thank you all, I solved … unfortunately I am so inexperienced in this matter that I had difficulty even understanding your answers, but thanks to Sandi (from polargraph forum) I managed to make the sketch work, I share with you his answer as well 'that someone else can solve the same problem:

"This is because the KeyEvent hasn’t been imported so Processing doesn’t know what it refers to. You could try adding:

import java.awt.event.KeyEvent; import java.util.Calendar;

to the beginning of your file. The next complaint will be one about not finding the file that’s referenced (called “delorien.jpg”) on the current first line of the file."

1 Like