• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Xarbrough · Jun 17, 2016 at 07:42 PM · c#editorhotkeys

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?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jessespike · Jun 17, 2016 at 08:22 PM 0
Share

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.

2 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Xarbrough · Jun 18, 2016 at 04:46 PM 0
Share

Too bad, but I can probably live with different shortcuts.

avatar image kartikips · Feb 23, 2017 at 05:50 AM 0
Share

This is a brilliant explanation but what if I want to change "F5" to "Space" is there anyway?

avatar image
0

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Xarbrough · Jun 18, 2016 at 04:49 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

158 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Initialising List array for use in a custom Editor 1 Answer

Texture swapped out works in editor but not in build 1 Answer

Game mechanic Tips 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges