# Sketch 84552 don't work, error

**URL:** <https://discourse.processing.org/t/sketch-84552-dont-work-error/17114>\
**Category:** Beginners\
**Created:** [January 16, 2020, 8:52am UTC](https://discourse.processing.org/t/sketch-84552-dont-work-error/17114 "2020-01-16T08:52:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![motorimicro](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@motorimicro](https://discourse.processing.org/u/motorimicro)\
**Post date:** [January 16, 2020, 8:52am UTC](https://discourse.processing.org/t/sketch-84552-dont-work-error/17114/1 "2020-01-16T08:52:48Z")

</div>

![Schermata 2020-01-16 alle 09.45.45](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/6661847b1996011c1ac5199f44f76cafdb4fb718.png)

here where download the sketch:

> **[Image based one line drawing - OpenProcessing](https://www.openprocessing.org/sketch/84552)**
>
> Another drawing machine, creates an one line drawing based on a given image.
> 
> Has two modes: Mode one always looks for the nearest neighbor and connects this two points. Mode two looks up for the 7 nearest neighbors and chooses one of these randomly....

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?

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [January 16, 2020, 9:39am UTC](https://discourse.processing.org/t/sketch-84552-dont-work-error/17114/2 "2020-01-16T09:39:56Z")

</div>

better use in PDE

[https://processing.org/reference/key.html](https://processing.org/reference/key.html)

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

```auto
println( key , keyCode );

```

---

<div class="post-metadata">

**Author:** ![motorimicro](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@motorimicro](https://discourse.processing.org/u/motorimicro)\
**Post date:** [January 16, 2020, 12:45pm UTC](https://discourse.processing.org/t/sketch-84552-dont-work-error/17114/3 "2020-01-16T12:45:59Z")

</div>

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!!

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [January 16, 2020, 1:28pm UTC](https://discourse.processing.org/t/sketch-84552-dont-work-error/17114/4 "2020-01-16T13:28:57Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [January 17, 2020, 3:23pm UTC](https://discourse.processing.org/t/sketch-84552-dont-work-error/17114/5 "2020-01-17T15:23:26Z")

</div>

> [@motorimicro](#):
>
> I get the error: if (keyCode == KeyEvent.VK\_1)

> <https://stackoverflow.com/questions/23252423/what-is-keyevent-vk-1/23252472#23252472>

> VK\_0 thru VK\_9 are the same as ASCII ‘0’ thru ‘9’

so, as @kll suggested:

`if ( key == '1' )`

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 17, 2020, 3:43pm UTC](https://discourse.processing.org/t/sketch-84552-dont-work-error/17114/6 "2020-01-17T15:43:07Z")

</div>

Question : what about import awt.\*;

Wouldn’t that import all the VK\_ constants?

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [January 17, 2020, 5:04pm UTC](https://discourse.processing.org/t/sketch-84552-dont-work-error/17114/7 "2020-01-17T17:04:26Z")

</div>

> [@jeremydouglass](#):
>
> KeyEvent.VK\_1

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 –

> **[keyCode / Reference](https://processing.org/reference/keyCode.html)**
>
> The variable keyCode is used to detect special keys such as the UP, DOWN, LEFT, RIGHT arrow keys and ALT, CONTROL, SHIFT. When checking for these keys, it can be useful to first chec…

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

---

<div class="post-metadata">

**Author:** ![motorimicro](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@motorimicro](https://discourse.processing.org/u/motorimicro)\
**Post date:** [January 25, 2020, 7:10pm UTC](https://discourse.processing.org/t/sketch-84552-dont-work-error/17114/8 "2020-01-25T19:10:12Z")

</div>

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."
