- Home /
Simple Scripting Question
What is the difference between GetKey and GetButton? Thanks
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.
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.