Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Use Escape key in-game without editor releasing cursor

Discussion in 'Editor & General Support' started by dhenion65, May 17, 2020.

  1. dhenion65

    dhenion65

    Joined:
    Dec 17, 2019
    Posts:
    21
    I can't find a way to change the Escape key binding in Unity - so when in play mode, hitting escape shows/releases the mouse cursor - which is great, but I want to use the escape key in my game to exit a menu, which does the exact opposite. So its difficult to debug that since Unity is always forcing a show cursor.

    Escape not listed anywhere in key bindings and that key shows greyed out in key bindings - wish I could just change that key mapping to something else so I could use Escape in game.

    Any way around this?
     
  2. DiegoDePalacio

    DiegoDePalacio

    Unity Technologies

    Joined:
    Oct 28, 2009
    Posts:
    506
    Hi @dhenion65,

    What you can do is to use precompilation defines in order to use a different key while you're in PlayMode for testing-only purposes while developing.

    Something like this:
    Code (CSharp):
    1. #if UNITY_EDITOR
    2.         if (Input.GetKey(KeyCode.Q))
    3. #else
    4.         if (Input.GetKey(KeyCode.Escape))
    5. #endif
    6.         {
    7.             // Your code here
    8.         }
    9.  

    Good luck with it!
     
    Joe-Censored likes this.
  3. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    And it's worth mentioning that this will only be the case in the Editor. In a build of your game, pressing escape won't show the mouse cursor unless you code it to do so.
     
    Joe-Censored likes this.
  4. dhenion65

    dhenion65

    Joined:
    Dec 17, 2019
    Posts:
    21
    Thank you @DiegoDePalacio - for now I've been manually changing the GetKey code while in editor then changing it back for a build - so this will help that for sure.
    And yes @dgoyette I realize that, just a pain that I can't debug that key in the editor playmode.
     
    DiegoDePalacio likes this.