# Program stopping after executing certain lines when handling key presses

**URL:** https://discourse.processing.org/t/program-stopping-after-executing-certain-lines-when-handling-key-presses/43838
**Category:** Processing.py
**Created:** [February 6, 2024, 1:25am UTC](https://discourse.processing.org/t/program-stopping-after-executing-certain-lines-when-handling-key-presses/43838 "2024-02-06T01:25:33Z")
**Posts on this page:** 1
**Showing post:** 2

<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: [February 6, 2024, 2:06am UTC](https://discourse.processing.org/t/program-stopping-after-executing-certain-lines-when-handling-key-presses/43838/2 "2024-02-06T02:06:44Z")

</div>

My advice when reading variable _key_ is to apply this code:  
`k = key.upper() if key != CODED else keyCode`

Then use local variable _k_ instead w/ capitalized letters like the example from this link:

> [@snowflake Snow!](https://discourse.processing.org/t/snow/7156/3):
>
> I’ve refactored the original code in order to cache all pre-calculated values. heavy_plus_sign However, it didn’t speed anything. Alas, I guess it’s got slightly slower! no_mouth Regardless, using FX2D instead of default JAVA2D is what actually makes the sketch race! racing_car """ Snow! (v1.1) by Sky (2019-Jan-04) mod GoToLoop (2019-Jan-07) https://Discourse.Processing.org/t/snow/7156/3 """ from math import copysign FLAKES, YMIN, YMAX = 1001, -500, 50 RANGE = tuple(range(FLAKES))…

```auto
    k = key.upper() if key != CODED else keyCode

    if k == 'W' or k == UP:
        for f in flakes: f.vel.y -= f.maps[2]

    elif k == 'S' or k == DOWN:
        for f in flakes: f.vel.y += f.maps[2]

    elif k == 'A' or k == LEFT:
        for f in flakes: f.vel.x -= f.maps[2]

    elif k == 'D' or k == RIGHT:
        for f in flakes: f.vel.x += f.maps[2]

```

> [@Eb3yr](#):
>
> `bodies.Append(`

Ru sure that method is capitalized? If that’s a list type, it’s lower case instead: `bodies.append(`

---

_[View the full topic](https://discourse.processing.org/t/program-stopping-after-executing-certain-lines-when-handling-key-presses/43838)._
