- Home /
Intercept Ctrl + S keyboard shortcut in editor for custom editor
I'm designing my own editor tool and want to implement Undo/Redo behaviour, as well as saving to a custom file format. I'd like to also use the standard keyboard shortcuts for my own tool and prevent Unity from calling its own methods. Basically, I want to intercept the Ctrl + S hotkey before Unity knows about it or prevent Unity from performing its action and instead perform my own.
Is this possible?
Don't think you can override the default hotkeys. You'll need to do "Shift + Ctrl + S" or similar ins$$anonymous$$d. Hopefully I'm wrong and someone can correct me on this.
Answer by TBruce · Jun 17, 2016 at 08:45 PM
You can not intercept built in Unity keyboard shortcuts.
You can however define your own to do what you want. In the sample editor script below I show you how to do the same thing with two different keyboard shortcuts.
using UnityEngine;
using UnityEditor;
using System.Collections;
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;
public class UnityExtededShortKeys : ScriptableObject
{
[MenuItem("HotKey/Run _F5")]
[MenuItem("HotKey/Run2 _%H")]
static void PlayGame()
{
EditorSceneManager.SaveScene(SceneManager.GetActiveScene(), "", false);
EditorApplication.ExecuteMenuItem("Edit/Play");
}
}
Here is a link to how to use Unity Editor Extensions.
Too bad, but I can probably live with different shortcuts.
This is a brilliant explanation but what if I want to change "F5" to "Space" is there anyway?
Answer by phxvyper · Jun 17, 2016 at 09:24 PM
You can't intercept Unity Shortcuts through Unity. However, you can intercept keyboard input to any software by using some more low-level stuff.
There is a library called Interception (click here) which will let you intercept and transform keyboard input.
You can make a program in a language of your choice that implements this, as long as that language supports native code importing. C# supports this.
Would this really work for overriding Unity hotkeys within the editor? I don't really see how it would do that. Also it seems a little convoluted for something that should just be a convenience for my level designers.
Your answer

Follow this Question
Related Questions
Initialising List array for use in a custom Editor 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Repaint EditorSettings inspector from custom menu item 1 Answer
Script Editors for Unity 3 Answers