• 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
4
Question by vexe · Dec 29, 2013 at 07:08 AM · editorkeycode

Send a key to the Editor?

Simple, how to send a key or a combo of keys to the editor? So like:

 Selection.objects = new Object[] { myObject; };
 SendKey(KeyCode.LeftCtrl | KeyCode.D); // for duplicate

or

 SendKey(KeyCode.F2); // for renaming

etc.

Is there some editor code that has this feature? If not, is there a platform-dependent way of doing this? or am I stuck with Winform and WinAPI stuff? (I'm on Windows)

Thanks :)

Comment
Add comment
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

2 Replies

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

Answer by ArkaneX · Feb 20, 2014 at 12:49 PM

I've just checked your other question, and here's the solution to send keys to focused window:

 var e = new Event { keyCode = KeyCode.F2, type = EventType.keyDown }; // or Event.KeyboardEvent("f2");
 EditorWindow.focusedWindow.SendEvent(e);
 EditorWindow.focusedWindow.SendEvent(Event.KeyboardEvent("x"));
 EditorWindow.focusedWindow.SendEvent(Event.KeyboardEvent("y"));
 EditorWindow.focusedWindow.SendEvent(Event.KeyboardEvent("z"));


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 vexe · Feb 20, 2014 at 12:56 PM 1
Share

I LOVE YOU!!! LOL

avatar image
2

Answer by frarees · Dec 30, 2013 at 05:53 PM

AFAIK it isn't possible to simulate input (i.e. create events from the void), despite I think you can send already triggered events on your current ScriptableObject to other ScriptableObjects. In your case, it seems you want the functionality behind those shortcuts.

For duplicate functionality over serializable objects check SerializedProperty.DuplicateCommand. For renaming on the project window, check ProjectWindowUtil and EndNameAction (use MonoDevelop's Assembly Browser to make things easier)

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 vexe · Feb 20, 2014 at 06:30 AM 0
Share
  • Sorry for the delay and thanks so much for this! - Although it's not what I'm looking for (looking for rename in hierarchy window, not project window), but it gave me other cool stuff! - Check this out http://pig893.hatenablog.com/entry/2014/01/28/140345 - This guy used ProjectWindowUtil to make a script creator using templates one makes himself! more useful than unity's templates which always get overwritten when you update --

For the rena$$anonymous$$g I first tried WinAPI's SendInput, to send an F2 manually - For some reason Creating a new go, selecting it and then sending an F2, didn't engage rename mode! Although I'm pretty sure that the key was sent (Tried it from a console app, sleep(5); / during this time, I select a go in Unity /sendkey(f2); and indeed, rename mode engages! but for some reason doing it inside unity doesn't seem to work :(

Here's what I'm attempting now, got really close this time! http://answers.unity3d.com/questions/644608/sending-a-rename-commandevent-to-the-hiearchy-almo.html

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

23 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

Related Questions

Engage "Rename" mode on a gameObject from editor code? 1 Answer

KeyCode in custom editor 2 Answers

Catch Ctrl+Z input in Editor 1 Answer

Creating Unity Editor Extension 3 Answers

How to hide parent in Hierarchy and maintain child? 0 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