# Issue with keyPressed

**URL:** <https://discourse.processing.org/t/issue-with-keypressed/15755>\
**Category:** Beginners\
**Created:** [November 24, 2019, 1:36am UTC](https://discourse.processing.org/t/issue-with-keypressed/15755 "2019-11-24T01:36:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [November 24, 2019, 1:36am UTC](https://discourse.processing.org/t/issue-with-keypressed/15755/1 "2019-11-24T01:36:12Z")

</div>

I want to add some key functionality to my program, it works fine for arrow keys but not for other keys

```auto
if(keyPressed && keyCode ==37){
            flyingx += 0.1;
          }
          if(keyPressed && keyCode ==39){
            flyingx -= 0.1;
          }
         
          if(keyPressed && keyCode == 87){
             ztoggle ++;
              ztoggle2 = 0;
              if(ztoggle==2){
               ztoggle = 0; 
              }}

```

it works if I remove keyPressed, but then the toggle function stops working.

---

<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:** [November 24, 2019, 1:49am UTC](https://discourse.processing.org/t/issue-with-keypressed/15755/2 "2019-11-24T01:49:35Z")

</div>

try a complete different concept:  
[How to get a turnkey!](https://discourse.processing.org/t/how-to-get-a-turnkey/15716/2) here

possibly you can build your toggle thing in?

---

<div class="post-metadata">

**Author:** ![unique\_username](https://avatars.discourse-cdn.com/v4/letter/u/a88e57/32.png) [@unique\_username](https://discourse.processing.org/u/unique_username)\
**Post date:** [November 24, 2019, 9:12pm UTC](https://discourse.processing.org/t/issue-with-keypressed/15755/3 "2019-11-24T21:12:41Z")

</div>

With the keyPressed function, I recommend only using _keyCode_ for arrows(keyCode==“UP”,keyCode==“DOWN”), instead for letters I would simply use

if(keyPressed) {  
if(key==‘lowercase letter’) {

---

<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:** [November 25, 2019, 1:16am UTC](https://discourse.processing.org/t/issue-with-keypressed/15755/4 "2019-11-25T01:16:38Z")

</div>

“isKeyDown()” -\> [Studio.ProcessingTogether.com/sp/pad/export/ro.9cfU11egvzT6G](http://Studio.ProcessingTogether.com/sp/pad/export/ro.9cfU11egvzT6G)
