# keyPressed and keyReleased with java(eclipse)

**URL:** <https://discourse.processing.org/t/keypressed-and-keyreleased-with-java-eclipse/12994>\
**Category:** Coding Questions\
**Created:** [July 26, 2019, 8:12am UTC](https://discourse.processing.org/t/keypressed-and-keyreleased-with-java-eclipse/12994 "2019-07-26T08:12:49Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [July 27, 2019, 11:47am UTC](https://discourse.processing.org/t/keypressed-and-keyreleased-with-java-eclipse/12994/3 "2019-07-27T11:47:38Z")

</div>

> [@vincentstrebelle](#):
>
> Hi i found the code “Player Move” from @GoToLoop and i have several questions.

I believe you’ve got it from here perhaps: ❓

- [Forum.Processing.org/two/discussion/8511/movement-code-messed-up#Item\_6](http://Forum.Processing.org/two/discussion/8511/movement-code-messed-up#Item_6)
- [sketchpad](http://Studio.ProcessingTogether.com/sp/pad/export/ro.91tcpPtI9LrXp)

> [@vincentstrebelle](#):
>
> `void keyPressed() { // Is there a way to use it in Java?`

What do you mean by that? This sketch is already cross-mode. ❎

That is, the same code runs on both offline Java Mode (Processing’s IDE) & online JavaScript Mode (Pjs): [ProcessingJS.org](http://ProcessingJS.org)

> [@vincentstrebelle](#):
>
> ```java
> d = dd; // DIAM?
> v = vv; // SPD?
> 
> ```

DIAM stands for diameter and SPD stands for speed. 🏎

> [@vincentstrebelle](#):
>
> `int r = d >> 1; // What's the purpose of the r here?`

`d >> 1` gets the half of _d_, which stands for diameter btW. Thus _r_ is radius. 🟢

B/c the sketch is using the default `ellipseMode(CENTER);`:

- [ellipseMode() / Reference / Processing.org](http://Processing.org/reference/ellipseMode_.html)

> The default mode is **ellipseMode(CENTER)** , which interprets the first two parameters of **ellipse()** as the shape’s center point, while the third and fourth parameters are its width and height.

And the coordinate pair origin of an **ellipse()** is its CENTER, knowing the RADIUS of it is essential for collision checks: ✔

- [Collision Detection](http://JeffreyThompson.org/collision-detection/circle-rect.php)

In this specific sketch, the collision check is to **constrain()** the **ellipse()** within the sketch’s rectangular canvas when we move it: 🧐  
`x = constrain(x + v*(int(isRight) - int(isLeft)), r, width - r);`

- [constrain() / Reference / Processing.org](http://Processing.org/reference/constrain_.html)

> [@vincentstrebelle](#):
>
> `// In Java I can't "link" the isUp, isDown, isRight and isLeft between move() and setMove().`

Again I don’t get what you mean. B/c we can totally copy & paste the whole code in Processing IDE’s Java Mode in order to run it offline. ☕

---

_[View the full topic](https://discourse.processing.org/t/keypressed-and-keyreleased-with-java-eclipse/12994)._
