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.
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");
}
}