Issue with keyPressed

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

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.

1 Like

try a complete different concept:
How to get a turnkey! here

possibly you can build your toggle thing in?

2 Likes

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’) {

“isKeyDown()” -> Studio.ProcessingTogether.com/sp/pad/export/ro.9cfU11egvzT6G