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,672
    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.
     
    zanouk, wlwl2, EyeSeeEm and 1 other person like this.
  2. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    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,672
    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?
     
    lucasjohansson and kungfooman like 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 ;-)
     
    CloudyVR, kungfooman and wh1t3rabbit like this.
  6. Unity_Flashbak

    Unity_Flashbak

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

    zagmodell

    Joined:
    Dec 27, 2012
    Posts:
    22
    this sucks
     
    SgerbwdGwyn, CloudyVR and kungfooman like this.
  8. Farresto

    Farresto

    Joined:
    Jan 20, 2016
    Posts:
    9
    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:
    16
    Aeroxima and kungfooman like 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:
    158
    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:
    3
    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.
     
    ahmedkhemiri466, wlwl2 and Flurgle like this.
  13. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,052
    Create two set of keys, one for editor and one for runtime then just use the conditional check for editor.
     
    wlwl2 likes this.
  14. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
    @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:
    9,052
  16. Soundwolf776

    Soundwolf776

    Joined:
    Mar 21, 2015
    Posts:
    17
    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.
     
  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:
    11
    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:
    31
    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?
     
    ribbanya likes this.
  20. wlwl2 likes this.
  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:
    34
    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...
     
    patrik-org likes this.
  23. patrik-org

    patrik-org

    Joined:
    Sep 10, 2012
    Posts:
    100
    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
     
    halley and twhittaker like this.
  24. ARGB32

    ARGB32

    Joined:
    Feb 20, 2013
    Posts:
    15
    zanouk, chaikadev, Tonio1308 and 4 others like this.
  25. Chalkcs

    Chalkcs

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

    todinger

    Joined:
    Oct 25, 2017
    Posts:
    4
    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.
     
    zanouk likes this.
  27. Microrican

    Microrican

    Joined:
    Aug 30, 2017
    Posts:
    2
    There really are not that many unity made games if we are being honest (unless you want to talk about the endless 1 level indie games being attempted full of bugs and crushed dreams).

    Especially in comparison to REAL game engines like Unreal or Havoc etc ... So im sure the games you see made from unity are all more or less workaround after workaround embedded into their sources to even get them to function at all.

    Then you sure do not hear of people making sequel games using unity like hmmmm did Assassins Creed come out with another unity version after their initial unity masterpiece(pile) ???

    Unity has a long way still to go to even claim they are an engine ..... an engine without networking of their own ...... UNET was a pile of junk and from what i see the next so called networking solution being worked on by unity seems to be a giant pile of trash as well !!

    Im sure my post will get yanked and i will get ANOTHER threatening email from a unity staff member but i do not really care im sick of the claims of how great Unity is and Will be in the future when they cant even get simple things right.

    In my experiences so far Unity is no more than a glorified Realm Crafter .... and you saw what happened to them.
     
  28. mashianov

    mashianov

    Joined:
    Mar 23, 2020
    Posts:
    13
    I can't understand how anybody's working in this pile of junk for 10 years.
    cmd-N which means new file in every other editor here destroys current scene with no way to recover other than VCS checkout, undo simply doesn't know about that operation.
    2018.3 has like 1/4 of shortucts available for override, others are casted iron.

    You can't disable editor shortcuts while in player mode in 7 years.

    How is that possible, Unity?
     
    ScottAdams likes this.
  29. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    If you can't override an editor shortcut you use in your game, just do your play testing in a build.
     
  30. mashianov

    mashianov

    Joined:
    Mar 23, 2020
    Posts:
    13
    This sounds like "if you can't test brakes in your car during driving school, go test them on roads after getting a license".
    Why should users do kludges for things expected from pretty much any game engine by default 8 years after first bug reports about it?
     
    visca_c likes this.
  31. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Because software development is problem solving. You've got a problem, so solve it. Aren't you sending builds to your game testers already? So why not just test using those same builds? You can also just remap problem inputs to different keys when detected you're in the editor. Crying on the forums for Unity to solve this problem for you is unlikely to work. Just figure out a solution, because if Unity was going to solve this for you it would have happened already.
     
  32. mashianov

    mashianov

    Joined:
    Mar 23, 2020
    Posts:
    13
    That's exactly what i'm saying. I already fixed it by an extra script from some knowledgeable guys from other topic where a lot of people cringe about that crap.

    What i meant is this engine is > 10 years old, and it's editor is still as crappy as vs code alpha version. Community and/or programmers aren't supposed to fix editor problems themsevles if it's not open-source free solution, that's a platform vendor's work in the first place.

    No basic features like support for shortcuts for all editor actions still even in 2019.x version is a total shame. Like, i still can't map "collapse/expand all" action from inspector to a keyboard, only mouse/trackpad. Rly? And you can't do that easily with addons as well, since there's no public api to refresh inspector window.

    And don't get me started on lack of search inside inspector. You've got classes/objects with like 300-1k lines of properties, and unity still didn't make a search so that you're forced to open search plugin for inspector in a separate window. Really?
     
    ScottAdams likes this.
  33. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    I've tried various solutions, along with some auto-profile creation scripts found on this thread: https://issuetracker.unity3d.com/issues/disable-editor-keyboard-shortcuts-while-playing

    But nothing so far handle the case I'm trying to get working: I want to be able to use the "Alt" key in my game as a held key, without it registering in Unity when in Play Mode. Currently, if I hold Alt in play mode, it changed the drag handle gizmo from one to another, which means I can't use the Alt key when playing.

    Has anyone found a solution to allowing the Alt key to be ignored by the Editor while in play mode? Or is this OS-level stuff that Unity has not control over?
     
    wlwl2 and ScottAdams like this.
  34. MikeWise

    MikeWise

    Joined:
    Dec 27, 2017
    Posts:
    14
    So how is Havok even a game engine? I see people writing this all the time, but surely it is just a Physics Engine, which sure, that is core, but not the whole thing by a long shot.
     
  35. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    There was a thing called Havok Vision Game Engine but that was discontinued in 2011, so they are now mostly know for there product Havok Physics.
     
  36. Major_Barnulf

    Major_Barnulf

    Joined:
    Aug 15, 2019
    Posts:
    1
    sooo... still nothing?
     
  37. jstine35

    jstine35

    Joined:
    Dec 23, 2017
    Posts:
    3
    I wrote what so far has been an effective solution to this problem by hooking Editor Shortcut Profile swap checks into all of the following:

    OnApplicationFocus

    EditorApplication.playModeStateChanged

    EditorApplication.pauseStateChanged


    It's necessary to hook all of these, in order to cover all the edge cases. I posted a gist:

    https://gist.github.com/jstine35/2a0b491cb1c1822debbc2571b487ad8d

    The remaining drawback is that you must still manually create a suitable player shortcut profile. This is apparently stored in the Windows Registry (why?? omg...) which makes it non-trivial to export or share a pre-fabricated editor. The process of creating my Player Shortcut Profile looked like this:

    unity-player-profile-create-small.gif
    (I recommend leaving CTRL+TAB shortcut bound, so you can still use keyboard to nav between Player and Editor.)

    If anyone has any tips on how to de-suckify that process shown above, please share! :)
     
    halley and zanouk like this.
  38. khan-amil

    khan-amil

    Joined:
    Mar 29, 2012
    Posts:
    206
    Another example on how not having an internal team developping games is hurting Unity.

    Still sad that there are no way to disable editor shortcuts, or to at least force consume inputs in the game before it reaches the rest of the editor..
     
  39. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I suspect you didn't read the thread all the way through. The original post is outdated. Many editor shortcuts can be managed via the Shortcuts Manager added in 2019.1.

    https://docs.unity3d.com/Manual/ShortcutsManager.html

    It looks like you can swap the currently active editor shortcut profile in code, so should be easy to simply set up a play mode profile that you enable automatically whenever you enter play mode.

    https://docs.unity3d.com/2019.4/Doc...agement.IShortcutManager-activeProfileId.html
     
    wlwl2 likes this.
  40. khan-amil

    khan-amil

    Joined:
    Mar 29, 2012
    Posts:
    206
    I did read it, but on re reading my post I wasn't clear enough and see where you got that impression.

    So yeah we can reassign shortcuts, but it's a pain in the ass as it involves re-creating a shrotcut preset (which unless it was changed involves de-assigning manually every shortcut), which you can't easily share with your team (on the upside though it's no longer stored in the registry but in the appdata folder).
     
    twhittaker, wlwl2 and Joe-Censored like this.
  41. ScottAdams

    ScottAdams

    Joined:
    Nov 23, 2016
    Posts:
    72
    This doesn't seem to work for the menu commands. For example while playing the game in the editor I hit Alt-W which is a debug command for the game. The windows sub menu though in the editor opens. There doesn't seem to be any way to redefine the alt-[keypress] commands for the editor menu!
     
  42. woodbyte

    woodbyte

    Joined:
    Apr 3, 2013
    Posts:
    2
    Ran into the same issue as OP, now in 2021.. so yeah, not going to rant about it (though I sure as hell feel like it) but instead leave a simple fix for it.

    First create a new shortcut profile (using Edit->Shortcuts then right click on the profile name and create a new one) and remove any bindings which conflict with your application.

    Then create a new editor script (Editor/PlayModeShortcuts.cs) with the following code:
    Code (CSharp):
    1.  
    2. [InitializeOnLoad]
    3. public static class EnterPlayModeBindings
    4. {
    5.     static EnterPlayModeBindings()
    6.     {
    7.         EditorApplication.playModeStateChanged += ModeChanged;
    8.         EditorApplication.quitting += Quitting;
    9.     }
    10.  
    11.     static void ModeChanged(PlayModeStateChange playModeState)
    12.     {
    13.         if (playModeState == PlayModeStateChange.EnteredPlayMode)
    14.             ShortcutManager.instance.activeProfileId = "Play";
    15.         else if (playModeState == PlayModeStateChange.EnteredEditMode)
    16.             ShortcutManager.instance.activeProfileId = "Default";
    17.     }
    18.  
    19.     static void Quitting()
    20.     {
    21.         ShortcutManager.instance.activeProfileId = "Default";
    22.     }
    23. }
    24.  
    And change "Play" with whatever name you used for your new profile.

    Hopefully the developers will soon find it in their hearts to disable some editor shortcuts (at least those that are not valid in play mode anyway like Alt-S) when the play view has focus, though judging by this thread we should absolutely not rely on that being the case.
     
    Last edited: Jan 8, 2021
  43. amisner2k

    amisner2k

    Joined:
    Jan 9, 2017
    Posts:
    43
    Just ran into this myself and @woodbyte 's solution was the simplest and most elegant. Thank you for that! I will add though, that Unity should disable all Editor shortcuts internally whenever a Game window is in focus and the Editor is in Play Mode. If this truly is a significantly hard challenge to solve, then I'd recommend someone at Unity write up a blog post detailing the issue and why it's taken so long, like they've done with other big issues that eventually got resolved (like Nested prefabs and the game timing issue).

    Anyway, thanks again @woodbyte , you saved my day. :)

    Edit: It should also be noted that it *can* be useful to have access to Editor shortcuts while testing your game in Play mode (maybe you want to quickly switch to Scene view, etc). So the Shortcut Editor Unity provided is the right way forward, but a project setting or editor preference that a user can toggle to "Disable Editor Shortcuts in Play Mode" would probably alleviate the final pain point most users experience regarding this.
     
    Last edited: Jan 14, 2021
  44. TrashCanHero

    TrashCanHero

    Joined:
    Jul 8, 2018
    Posts:
    4
    This thread was made in 2013, 8 years later and we've finally found a pretty hacky solution to a problem unity has just straight up ignored. Now, I love unity, it's my personal favorite when talking about engines that I have used. But the fact that they have not only refused to fix this hyper simple problem, but just straight up ignoring it and even going as far as to set any issue opened as postponed because they don't wanna touch. It almost makes me scared for how bad the codebase for the engine is if they don't want to even try...
     
  45. amisner2k

    amisner2k

    Joined:
    Jan 9, 2017
    Posts:
    43
    I imagine it's to do with priorities. Despite what it looks like this is likely not something many users have an issue with. I've been using Unity off and on generally for about 3 years or so and this is the first I've encountered it. Not saying it isn't a good issue to solve just that there are probably bigger fish for the team to fry.
     
  46. Supergeek

    Supergeek

    Joined:
    Aug 13, 2010
    Posts:
    103
    Unity needs an in-house game dev team so they can go through some of the same pain points we have. Another hearty thank you to @woodbyte for posting a straightforward workaround.
     
    amisner2k likes this.
  47. daryatalia98

    daryatalia98

    Joined:
    Feb 24, 2021
    Posts:
    1
    As of 2/24/2021, and the alt-[key] combo (in my case alt-space) is still up in the air.
     
  48. Marc-Saubion

    Marc-Saubion

    Joined:
    Jul 6, 2011
    Posts:
    655
    Thanks a lot @woodbyte . You forgot the using directive at the top. Here they are for those who are missing them.

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEditor.ShortcutManagement;
    3.  
    4. [InitializeOnLoad]
    5. public static class EnterPlayModeBindings
    6. {
    7.     static EnterPlayModeBindings()
    8.     {
    9.         EditorApplication.playModeStateChanged += ModeChanged;
    10.         EditorApplication.quitting += Quitting;
    11.     }
    12.  
    13.     static void ModeChanged(PlayModeStateChange playModeState)
    14.     {
    15.         if (playModeState == PlayModeStateChange.EnteredPlayMode)
    16.             ShortcutManager.instance.activeProfileId = "Play";
    17.         else if (playModeState == PlayModeStateChange.EnteredEditMode)
    18.             ShortcutManager.instance.activeProfileId = "Default";
    19.     }
    20.  
    21.     static void Quitting()
    22.     {
    23.         ShortcutManager.instance.activeProfileId = "Default";
    24.     }
    25. }
    I saw a massive improvement on my performances. Working with a french keyboard, I was hitting ctrl +z all the time. I almost left a bad review to an asset store creator because of Unity.

    One last finishing touch thing to do will be to swich from both profile depending on the selected window so this only affect "Game". I'm too busy to do that right away so if anybody wants to try it, here is the API: https://docs.unity3d.com/ScriptReference/EditorWindow-focusedWindow.html
     
    Last edited: Feb 28, 2021
    zanouk, GabrielWink and riffing like this.
  49. Darkenstein

    Darkenstein

    Joined:
    Oct 24, 2016
    Posts:
    4
    Extended version of @woodbyte 's solution if you need to disable shortcuts completely.

    Pros:
    - disables all shortcuts except Ctrl+P (even Alt+[letter] and Alt+Space)
    - creates "Play" profile automatically
    Cons:
    - window title and menu are temporarily hidden
    - uses Windows API

    Code (CSharp):
    1. using System;
    2. using System.Linq;
    3. using System.Runtime.InteropServices;
    4. using System.Text;
    5. using UnityEditor;
    6. using UnityEditor.ShortcutManagement;
    7. using UnityEngine;
    8.  
    9. [InitializeOnLoad]
    10. public static class PlayModeHack
    11. {
    12.     static PlayModeHack()
    13.     {
    14.         EditorApplication.playModeStateChanged += PlayModeStateChanged;
    15.         EditorApplication.quitting += Quitting;
    16.     }
    17.  
    18.     private static void PlayModeStateChanged(PlayModeStateChange playModeStateChange)
    19.     {
    20.         switch (playModeStateChange)
    21.         {
    22.             case PlayModeStateChange.EnteredPlayMode:
    23.                 if (ShortcutManager.instance.GetAvailableProfileIds().Contains("Play"))
    24.                 {
    25.                     ShortcutManager.instance.activeProfileId = "Play";
    26.                 }
    27.                 else
    28.                 {
    29.                     ShortcutManager.instance.CreateProfile("Play");
    30.                     ShortcutManager.instance.activeProfileId = "Play";
    31.  
    32.                     foreach (string shortcutId in ShortcutManager.instance.GetAvailableShortcutIds())
    33.                     {
    34.                         if (shortcutId != "Main Menu/Edit/Play")
    35.                         {
    36.                             ShortcutManager.instance.RebindShortcut(shortcutId, ShortcutBinding.empty);
    37.                         }
    38.                     }
    39.                 }
    40.  
    41.                 new GameObject("PlayModeHack", typeof(PlayModeHackMonoBehaviour));
    42.                 break;
    43.  
    44.             case PlayModeStateChange.ExitingPlayMode:
    45.                 ShortcutManager.instance.activeProfileId = "Default";
    46.                 break;
    47.         }
    48.     }
    49.  
    50.     private static void Quitting()
    51.     {
    52.         ShortcutManager.instance.activeProfileId = "Default";
    53.     }
    54. }
    55.  
    56. public class PlayModeHackMonoBehaviour : MonoBehaviour
    57. {
    58.     private delegate int EnumThreadWndProc(IntPtr hWnd, IntPtr lParam);
    59.  
    60.     [DllImport("user32.dll")]
    61.     static extern int EnumThreadWindows(uint dwThreadId, EnumThreadWndProc lpfn, IntPtr lParam);
    62.     [DllImport("kernel32.dll")]
    63.     static extern uint GetCurrentThreadId();
    64.     [DllImport("user32.dll")]
    65.     static extern int GetClassNameA(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
    66.  
    67.     [DllImport("user32.dll")]
    68.     private static extern IntPtr GetMenu(IntPtr hWnd);
    69.     [DllImport("user32.dll")]
    70.     private static extern int SetMenu(IntPtr hWnd, IntPtr hMenu);
    71.     [DllImport("user32.dll")]
    72.     private static extern int DrawMenuBar(IntPtr hWnd);
    73.  
    74.     [DllImport("user32.dll")]
    75.     private static extern int GetWindowLongA(IntPtr hWnd, int nIndex);
    76.     [DllImport("user32.dll")]
    77.     private static extern int SetWindowLongA(IntPtr hWnd, int nIndex, int dwNewLong);
    78.  
    79.     private const int GWL_STYLE = -16;
    80.  
    81.     private const int WS_CAPTION = 0x00C00000;
    82.     private const int WS_SYSMENU = 0x00080000;
    83.  
    84.     private IntPtr hFrameWnd;
    85.     private IntPtr hFrameMenu;
    86.  
    87.     private void Awake()
    88.     {
    89.         int EnumThreadWndProc(IntPtr hWnd, IntPtr lParam)
    90.         {
    91.             StringBuilder className = new StringBuilder(64);
    92.             GetClassNameA(hWnd, className, 64);
    93.             if (className.ToString() == "UnityContainerWndClass")
    94.             {
    95.                 hFrameWnd = hWnd;
    96.                 hFrameMenu = GetMenu(hWnd);
    97.                 return 0;
    98.             }
    99.             return 1;
    100.         }
    101.  
    102.         EnumThreadWindows(GetCurrentThreadId(), EnumThreadWndProc, IntPtr.Zero);
    103.  
    104.         gameObject.hideFlags = HideFlags.HideInHierarchy;
    105.  
    106.         GameObject.DontDestroyOnLoad(gameObject);
    107.     }
    108.  
    109.     private void Update()
    110.     {
    111.         if (Time.frameCount == 3)
    112.         {
    113.             SetWindowLongA(hFrameWnd, GWL_STYLE, GetWindowLongA(hFrameWnd, GWL_STYLE) & ~(WS_CAPTION | WS_SYSMENU));
    114.  
    115.             SetMenu(hFrameWnd, IntPtr.Zero);
    116.             DrawMenuBar(hFrameWnd);
    117.         }
    118.     }
    119.  
    120.     private void OnDestroy()
    121.     {
    122.         SetWindowLongA(hFrameWnd, GWL_STYLE, GetWindowLongA(hFrameWnd, GWL_STYLE) | (WS_CAPTION | WS_SYSMENU));
    123.  
    124.         SetMenu(hFrameWnd, hFrameMenu);
    125.         DrawMenuBar(hFrameWnd);
    126.     }
    127. }
     
    GRADE2FZ, zanouk, fizzd and 1 other person like this.
  50. ell1e

    ell1e

    Joined:
    Apr 4, 2021
    Posts:
    15
    This really should be fixed. In play mode, CTRL and shift and other special keys simply need to go exclusively to the game and not to the editor, it's as simple as that. Please fix it, Unity Technologies...?