# Pushing a key for a game (player walking)

**URL:** https://discourse.processing.org/t/pushing-a-key-for-a-game-player-walking/40717
**Category:** Project Guidance
**Created:** [January 26, 2023, 6:49am UTC](https://discourse.processing.org/t/pushing-a-key-for-a-game-player-walking/40717 "2023-01-26T06:49:26Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![king\_B99](https://avatars.discourse-cdn.com/v4/letter/k/258eb7/32.png) [@king\_B99](https://discourse.processing.org/u/king_B99)
#### Post date: [January 26, 2023, 6:49am UTC](https://discourse.processing.org/t/pushing-a-key-for-a-game-player-walking/40717/1 "2023-01-26T06:49:26Z")

</div>

Hello everyone I am trying to make a code that will act like an auto clicker but works for keys on the keyboard. E.X. Im in a game and for some reason, I want to keep walking around every now and then how can I just push say the letter “Z” and the payer will move in intervals?

---

<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 26, 2023, 7:50am UTC](https://discourse.processing.org/t/pushing-a-key-for-a-game-player-walking/40717/2 "2023-01-26T07:50:31Z")

</div>

> [@king\_B99](#):
>
> letter “Z” and the player

**Register key Z**

```auto

void keyPressed() {
   if (key=='Z') {
       startWalking=true; 
   }
}

```

**Declare this marker:**

before setup `boolean startWalking=false;`

**and in draw()**

```auto
if(startWalking){
   if(millis() - timer > randomTime) {
      walk(); 
      timer=millis(); 
      randomTime=random(700, 2200); // next walking occurs between 0.7 sec and 2.2 sec
      i++; 
      // stop 
      if(i>10) {
         i=0; 
         startWalking=false;
      }
   }
}

```

**Remark 1**

Declare timer and randomTime as int before setup()

**Remark 2**

You can have a 2nd timer to pause between intervals so he walks, stops, walks, several times.

Chrisir
