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 Alex-Chouls · May 26, 2011 at 12:08 AM · editorkeyboardkeyboard shortcut

Platform independent keyboard modifiers for shortcuts

I'm implementing keyboard shortcuts in an editor window and was wondering if there's a standard way to get platform independent modifier keys. For example, keyboard shortcuts use Control on a PC and Command on a Mac.

Right now I use a small utility function:

 public static bool CommandKeyDown()
 {
     if (Application.platform == RuntimePlatform.OSXEditor)
     {
         return Event.current.command;
     }
     return Event.current.control;
 }

But it seems like Unity would have some built in way to handle this kind of thing...? Obviously not urgent since I have a workaround, but would like to tidy this up if possible.

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

3 Replies

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

Answer by Alex-Chouls · Jun 14, 2011 at 05:46 PM

Actually found the exact thing I was looking for: EditorGUI.actionKey

"Is the platform-dependent "action" modifier key held down? (Read Only)

The key is Command on Mac OS X, Control on Windows."

http://unity3d.com/support/documentation/ScriptReference/EditorGUI-actionKey.html

Comment
Add comment · 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
0
Best Answer

Answer by Bunny83 · May 26, 2011 at 02:28 AM

Ok it's quite common that the equivalent on mac for the control key is the command key but that's not really a rule or standard. Event.current.command also works on windows machines but it's the windows key. I don't see any reason why unity should provide a function that will do exactly what you did.

Actually you aren't talking to unity here ;) We are the community that is using Unity. If you have a feature request for Unity post it on feedback.unity3d.com

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 Alex-Chouls · Jun 03, 2011 at 02:24 PM 0
Share

Thanks. Unity itself establishes some conventions (e.g., keyboard shortcuts like copy/paste use ctrl on windows and command on mac) so was hoping there might be some internal abstraction for tool developers looking for the "platform dependent keyboard shortcut modifier key"!

There are enough little differences in the way the unity editor code works on mac and pc to make it a bit of a pain to standardize the behavior, so personally I'd welcome anything Unity can do to abstract away platform differences. It also seems in line with their design philosophy, given Unity's custom platform independent GUI.

avatar image
0
Best Answer

Answer by Eric5h5 · May 26, 2011 at 02:28 AM

There isn't any built-in way, no. After all, Event.current.control exists on OS X as well, whereas there is no real equivalent to the Command key on Windows (I understand the Windows key can't really be used in the same way). I don't see anything untidy about your function.

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 Alex-Chouls · Jun 03, 2011 at 02:28 PM 0
Share

Thanks Eric5h5. The thing I don't like about the function is that I have to remember to use it! ;) Something like EventType.shortcut$$anonymous$$odifier$$anonymous$$ey which mapped to Ctrl on pc and Command on mac would be less error prone I$$anonymous$$O.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Keyboard fails to work during play mode but OK in build. 1 Answer

Context Menu keyboard shortcut 1 Answer

Keyboard Ctrl + 1 Input Problem 3 Answers

Latest version of Unity Editor (4.5) takes over media keys 1 Answer

What changes mouse/keyboard speed when editing? 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