Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
5
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.

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

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges