# \[Phaser 3\] Need double keyboard input for function

**URL:** <https://phaser.discourse.group/t/phaser-3-need-double-keyboard-input-for-function/5346>\
**Category:** Phaser 3\
**Created:** [February 27, 2020, 10:52am UTC](https://phaser.discourse.group/t/phaser-3-need-double-keyboard-input-for-function/5346 "2020-02-27T10:52:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lol](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/lol/32/2772_2.png) [@lol](https://phaser.discourse.group/u/lol)\
**Post date:** [February 27, 2020, 10:52am UTC](https://phaser.discourse.group/t/phaser-3-need-double-keyboard-input-for-function/5346/1 "2020-02-27T10:52:54Z")

</div>

Hello hello, been trying to troubleshoot an issue I’ve been having regarding scene transitions and keyboard inputs, to no avail.

So basically I want to have a main menu scene and an options screen, and if I press enter while a line of text is selected on the main menu, the main menu scene will sleep/pause/shutdown/anything to make it disappear, and then the options scene will appear, and vice versa with options screen --\> main menu.

After some experimenting with the scene transitions on offer, I settled on using switch() for both transitions, which also saves any changed values in the options scene. However this causes an issue where I need to press enter _twice_ to switch to the options scene, after I go main menu --\> options --\> main menu. The first time transitioning from main menu to options only requires one press of enter like I intended, but afterwards it always requires two presses of enter to open the options screen.

This issue also only occurs in the main menu --\> options transition, not the other way around. It also happens with some transitions between the menu and other scenes, but I figured that I’d be able to fix those if I can fix the main menu --\> options transition first.

All functions are called in create(), and keyEnter is a variable defined in create():

```
 keyEnter = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.ENTER);

```

Function that calls the transition to the options page:

```
  menuOptionEnter() {
    // Does certain things when enter is pressed on a certain selection

    keyEnter.on('down', function() {
      if (mainMenuSelection == 1) {
        // Starts game
        console.log('start game');
      } else if (mainMenuSelection == 2) {
        // Continues the previous game if there was one in progress
        console.log('continue');
      } else if (mainMenuSelection == 3) {
        // Starts the tutorial
        console.log('tutorial');
      } else {
        // Moves to the options page
        this.scene.switch('options');
      }
    }, this);
  }

```

Options --\> main menu:

```
  optionsExit() {
    // Exits to main menu when escape is pressed
    this.input.keyboard.on('keydown', function(event) {
      switch (event.key) {
        case 'Escape':
        console.log('menu');
        this.scene.switch('gameMenu');
        break;
      }
    }, this);
  }

```

Another function main menu --\> another scene, also affected by the double press issue:

```
  menuExit() {
    // Escapes to splash screen when 'escape' is pressed
    this.input.keyboard.on('keydown', function(event) {
      switch (event.key) {
        case 'Escape':
        this.scene.switch('splashScreen');
        break;
      }
    }, this);
  }

```

Help would be super appreciated, spent a couple of days trying to figure this out and I’m at a complete dead end, perhaps I wasn’t transitioning between scenes correctly?  
I’m not sure how much of my code I need to post to have sufficient detail for a solution, but I hope this will be of some use if the issue is obviously about scene transition stuff.

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [February 27, 2020, 3:19pm UTC](https://phaser.discourse.group/t/phaser-3-need-double-keyboard-input-for-function/5346/2 "2020-02-27T15:19:05Z")

</div>

Can you try

```javascript
// Moves to the options page
this.scene.switch('options');
keyEnter.reset();

```

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [February 27, 2020, 3:27pm UTC](https://phaser.discourse.group/t/phaser-3-need-double-keyboard-input-for-function/5346/3 "2020-02-27T15:27:05Z")

</div>

Or

```
this.input.keyboard.resetKeys()
```

---

<div class="post-metadata">

**Author:** ![lol](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/lol/32/2772_2.png) [@lol](https://phaser.discourse.group/u/lol)\
**Post date:** [February 28, 2020, 12:59am UTC](https://phaser.discourse.group/t/phaser-3-need-double-keyboard-input-for-function/5346/4 "2020-02-28T00:59:09Z")

</div>

Both work great, far simpler than I expected, thanks :))

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [February 28, 2020, 1:50am UTC](https://phaser.discourse.group/t/phaser-3-need-double-keyboard-input-for-function/5346/5 "2020-02-28T01:50:05Z")

</div>

I couldn’t reproduce the issue 🤷‍♀️ but if it works 😄 …

https://codepen.io/samme/embed/preview/XWbReRd?height=300&slug-hash=XWbReRd&default-tabs=js,result&host=https://codepen.io
