Search Unity

Unwanted editor hotkeys in game mode

Discussion in 'Editor & General Support' started by guycalledfrank, May 13, 2013.

  1. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,165
    Hi, everyone.

    So I was going to use the holding of a Ctrl key for crouching of my game character, while moving it with typical WASD - nothing too fancy, quite usual key mappings.
    However, it seems to be impossible in editor's game mode, because Ctrl+A, Ctrl+S and Ctrl+D are not detected by Event.keyCode and still act as editor hotkeys, while doing nothing useful at all except for Ctrl+S which stops the game to show me the error "You must exit play mode to save the scene!". Well what's the point of even detecting these hotkeys in game mode?

    Is there any workaround for making Ctrl useable in game mode? I obviously can use some different key, but I really used to Ctrl for crouching and there is no adequate reason to change my habits.
     
    kungfooman likes this.
  2. OutCyder

    OutCyder

    Joined:
    Mar 19, 2009
    Posts:
    2,154
    Go to PREFERENCES and redefine the keys shortcuts.

    Personally, I erased all the terrain shortcuts because they were messing with navigation.

    Sure is, when on play mode the editor shortcuts would be good if disabled.
     
  3. guycalledfrank

    guycalledfrank

    Joined:
    May 13, 2013
    Posts:
    1,165
    Oh yes, I forgot to mention that THESE hotkeys are not redefinable!
     
  4. CinnoMan

    CinnoMan

    Joined:
    Jan 27, 2014
    Posts:
    16
    Hi!

    I've just run into the same problems: My game's control scheme has cases where "ctrl" and "s" are pressed simultaneously, which the unity editor interprets as the saving shortcut.

    Is there a way to disable editor hotkeys while in game mode, or another workaround for this issue? Surely wasd + ctrl isn't such an unusual control scheme, that Mr. F and I are the only ones who ran into it, right?
     
    kungfooman likes this.
  5. Zaddo67

    Zaddo67

    Joined:
    Aug 14, 2012
    Posts:
    489
    Bump.

    Typical First person shooter controls are "ctrl" to crouch and "s" to move backwards. So "ctrl+s" is moving backwards while crouched.

    Can unity editor shortcuts be disabled while playing ...except "ctrl+p", i need that ;-)
     
    kungfooman and wh1t3rabbit like this.
  6. Unity_Flashbak

    Unity_Flashbak

    Joined:
    Jul 15, 2015
    Posts:
    3
    Same problem for ctrl + wasd here... any solution ? :/
     
    kungfooman likes this.
  7. zagmodell

    zagmodell

    Joined:
    Dec 27, 2012
    Posts:
    22
    this sucks
     
    kungfooman likes this.
  8. Farresto

    Farresto

    Joined:
    Jan 20, 2016
    Posts:
    7
    Having the same problem, it's been years this problem is happening - no solution or workaround exists yet?
     
    kungfooman likes this.
  9. thomak-dev

    thomak-dev

    Joined:
    Mar 8, 2015
    Posts:
    15
    kungfooman likes this.
  10. kungfooman

    kungfooman

    Joined:
    Jun 3, 2014
    Posts:
    7
    I NEED THIS, COME ON UNITY. Editor Shortcuts in Play Mode steals all the shortcuts I need ingame!
     
  11. Zogg

    Zogg

    Joined:
    Mar 28, 2009
    Posts:
    157
    Same problem here. I'm implementing an undo system, but when I want to test it, Unity messes things up by undoing stuff in the editor.
     
  12. ANicholas

    ANicholas

    Joined:
    Nov 20, 2013
    Posts:
    1
    Same issue as Zogg; I have an in-game level editor where I've setup the CTRL-Z hotkey to undo the last action, which of course is conflicting with the editor.
     
    Flurgle likes this.
  13. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    7,975
    Create two set of keys, one for editor and one for runtime then just use the conditional check for editor.
     
  14. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    371
    @zombiegorilla, is there a resource we can use for more information on this? I just ran into the problem.
     
  15. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    7,975
  16. Soundwolf776

    Soundwolf776

    Joined:
    Mar 21, 2015
    Posts:
    14
    Bump, I guess?

    Having two sets of keys is not an answer at all. A game with a complex control scheme must be tested with a specific set of keys in mind to see if it's convenient to access and use them. It's rather critical for UX design.

    I don't see any other way now but to build the project each time I need to see if the control scheme is ok. But UX issues generally require iterative approach, so it means a lot of builds, and this is just a crazy waste of time because of an issue that shouldn't be incredibly hard to resolve on Unity's side.

    So, please, add the "If (Application.isEditor)" on the engine side.
     
    sand_lantern likes this.
  17. dartyushin

    dartyushin

    Joined:
    Jan 22, 2018
    Posts:
    1
    This allows us to disable our custom hotkeys in our code - but not Unity's default hotkeys! What if i want Ctrl-S to stop being "Save Scene" and start being "Do Something In-game" during play mode inside the editor? We do not want to disable our custom hotkeys, but Unity's default ones!

    More than that, Application.isEditor is always true in editor, play mode or not. We could also use Application.isPlaying, but again, it works only for our own code and thus - our own hotkeys. We still need a real solution here.
     
  18. albrechtjess

    albrechtjess

    Joined:
    Oct 11, 2017
    Posts:
    1
    I agree it'd be great to disable shortcuts mid game scene. A temporary work around for me was just testing my crouching functionality with a Build and Run and it worked as expected though this is only a short term solution.
     
  19. Clonkex

    Clonkex

    Joined:
    Jul 31, 2012
    Posts:
    12
    Bump. Surely no one puts up with this? It seems like a major oversight. How on earth are there so many Unity-made games with such a critical flaw in the testing process?
     
  20. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    4,645
  21. Bardian25

    Bardian25

    Joined:
    Mar 5, 2018
    Posts:
    3
    The easiest way I have found to deal with this is to:

    1. Open the "Edit" menu, select "Shortcuts...", this will open the window for editing the in-editor keyboard shortcuts.
    2. Use the drop-down tab in the upper left corner of the shortcuts window to make a new profile in case you actually want default shortcuts for something later.
    3. Disable or reassign problematic shortcuts

    Scrolling through the command list can be quite tedious but if you are just getting rid of a shortcut you need only to right click on the key on the virtual keyboard, highlight the function you wish to remove, and select the "Remove Shortcut" pop-out.

    Shortcuts involving combos with shift, alt*, or ctrl can be accessed the same way, by highlighting whichever of those keys is in the shortcut with a left click on the virtual keyboard, than right clicking on the other key in the combination and proceeding with the removal of the shortcut.

    *edit: alt combined with certain keys will still open the editor menus, there may be other exceptions I have not encountered.

    Would still be great if someday editor shortcuts are simply disabled when the game window is selected in play mode, but our engine-eers seem to have their plates quite full of late.

    Hope this helps ^_^
     
    Last edited: Apr 28, 2019
  22. unitylepi

    unitylepi

    Joined:
    May 21, 2018
    Posts:
    11
    Probably the same issue, my program implements an undo buffer, using ctrl-z. However, I cannot test it in the editor because Unity starts doing it's own undo actions. I could imagine a cool feature where editor short-cuts are not active during game testing, only during real edit mode... makes sense...

    Guess I'll test with ctrl-x and set it back to z later...
     
    exmakina likes this.
  23. exmakina

    exmakina

    Joined:
    Sep 10, 2012
    Posts:
    60
    I'm creating an in-game editor with and I need to capture CTRL+s, CTRL+z, etc. Using other shortcuts while in the editor does not work as it's meant to be used in the editor and expecting the user to use other keyboard shortcuts is not an acceptable. I just need a simple way to disable editor keyboard shortcuts while playing. Something like:

    EditorApplication.disableKeyboardShortcutsWhilePlaying = true;


    https://issuetracker.unity3d.com/issues/disable-editor-keyboard-shortcuts-while-playing
     
  24. ARGB32

    ARGB32

    Joined:
    Feb 20, 2013
    Posts:
    6
    Clonkex likes this.
  25. Chalkcs

    Chalkcs

    Joined:
    Apr 23, 2013
    Posts:
    1
    How is this STILL thing? This is a major issue, and a crucial feature that SURELY can't be that difficult to solve?
     
  26. todinger

    todinger

    Joined:
    Oct 25, 2017
    Posts:
    2
    Give them time, it's only been six years. <_<

    I was looking for this because I was mildly annoyed that the editor window kept moving because I typed "f" in a text input in the game on occasion so I'm not gonna bother messing with this, but I do have a suggestion for a workaround for those of you for whom this is a serious problem: AutoHotkey.
    Make an AutoHotkey script that only triggers on the Unity editor window, and map the keys you want to editor variants.
    I.e.:
    1. In your game, have two sets of shortcuts, one that you actually want and one for when you run it in the editor. The while-in-editor keys can be something very inconvenient, like Ctrl+Alt+WinKey+Shift+F7. Just make sure it's not something that's used anywhere.
    2. Condition the keyboard shortcuts in the game to use the appropriate set when you're in the editor and when you're not.
    3. Set a hotkey for running/stopping the game from the editor. I set mine to F5 and I don't remember what the original one was (Ctrl+P maybe?)
    4. Make an AutoHotkey script which toggles whenever you press the play/stop key.
    5. Map the set of real keys to the set of fake keys when the script is toggled.
    6. Make sure you use the hotkey to start/stop the game.
    Example AHK script which maps Ctrl+Z to Ctrl+Alt+Shift+F1 and some others similarly:

    Code (csharp):
    1. #if WinActive("ahk_exe C:\Program Files\Unity\Hub\Editor\2019.2.17f1\Editor\Unity.exe")
    2.  
    3. ; The tilde catches the hotkey but also lets it through, so Unity would still run the game
    4. ~F5::PlayMode := !PlayMode
    5.  
    6. ; ^ for ctrl, ! for alt, + for shift and # for WinKey (which I didn't use here; the # in #if is unrelated)
    7. #if WinActive("ahk_exe C:\Program Files\Unity\Hub\Editor\2019.2.17f1\Editor\Unity.exe") and PlayMode
    8. ^z::^!+F1
    9. ^s::^!+F2
    10. w::^!+w
    11. s::^!+s
    12. a::^!+a
    13. d::^!+d
    Of course, replace the path of the Unity executable to your own, or you can have it look at window titles instead.
    I tested this and it worked for me.
    Mind that this won't help you much if what you want to test includes typing, as you won't be able to type the letters you disable.

    Anyway, hope this helps somebody.
     
unityunity