Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 MrSplosion · Dec 09, 2010 at 10:26 PM · guiinputmanagergetkeydifferencegetbutton

Simple Scripting Question

What is the difference between GetKey and GetButton? 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
2
Best Answer

Answer by skovacs1 · Dec 09, 2010 at 10:34 PM

Check out the Input Manager docs.

GetKey gets a named key by code. You cannot change the meaning of the key codes and they must be from the list in the following block quote:

Button Names

 <p>To map a key to an axis, you have to enter the key's name in the Positive Button or Negative Button property in the Inspector.</p>
 
 <p>The names of keys follow this convention:</p>
 
 <ul>
 <li>Normal keys: "a", "b", "c" ...</li>
 <li>Number keys: "1", "2", "3", ...</li>
 <li>Arrow keys: "up", "down", "left", "right"</li>
 <li>Keypad keys: "<a href="http://unity3d.com/support/documentation/Manual/Input.html" rel="nofollow">1</a>", "<a href="http://unity3d.com/support/documentation/ScriptReference/Input.GetKey.html" rel="nofollow">2</a>", "[3]", "[+]", "[equals]"</li>
 <li>Modifier keys: "right shift", "left shift", "right ctrl", "left ctrl", "right alt", "left alt", "right cmd", "left cmd"</li>
 <li>Mouse Buttons: "mouse 0", "mouse 1", "mouse 2", ...</li>
 <li>Joystick Buttons (from any joystick): "joystick button 0", "joystick button 1", "joystick button 2", ...</li>
 <li>Joystick Buttons (from a specific joystick): "joystick button 0", "joystick button 1", "joystick 1 button 0", ...</li>
 <li>Special keys: "backspace", "tab", "return", "escape", "space", "delete", "enter", "insert", "home", "end", "page up", "page down"</li>
 <li>Function keys: "f1", "f2", "f3", ... </li>
 </ul>
 
 <p>The names used to identify the keys are the same in the scripting interface and the Inspector.</p>
 
 <p>value = Input.GetKey ("a"); </p>

GetButton gets a button input defined in the Input Manger. You define what these are and, if you allow them to, the user can configure these. Re-configurability is what Buttons are truly good for. Because you define these, you can define multiple buttons with the same name that have different keys, like the button "Fire1" being "enter", "joystick button 0" and "mouse 0" all at the same time so that your code will work the same without having to check each of those inputs explicitly and it is also fairly simple to change these in the Input manager without changing your code.

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
1

Answer by Eric5h5 · Dec 09, 2010 at 10:41 PM

GetKey gets a specific key, GetButton gets a virtual button, which can be anything (keyboard key, mouse button, joystick button, etc.) and can be changed by the user in the launch dialog if running a stand-alone.

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

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

No one has followed this question yet.

Related Questions

Trying to stop or change an if 1 Answer

Get pressed Keyboard key after pressing UI Button 0 Answers

replace Input.GetKey for mobile input 1 Answer

Animation replaying every frame... 1 Answer

Why Use InputManager over the easy transform.Translate? 1 Answer


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