Important: Input Manager is a legacy feature and not recommended for new projects. For new projects you should use the Input System Package. |
The Input Manager window allows you to define input axes and their associated actions for your Project. To access it, from Unity’s main menu, go to Edit > Project Settings, then select Input Manager from the navigation on the right.
The Input Manager uses the following types of controls:
The Physical keys option allows you to map key codes to the physical keyboard layout, rather than to the language-specific layout that may vary between users in different regions.
For example, on some keyboards the first row of letters reads “QWERTY”, and on others it reads “AZERTY”. This means if you scripted specific controls to use the well known “WASD” keys for movement, they would not be in the correct physical arrangement (like the arrow-key arrangement) on an AZERTY-layout keyboard.
With Physical Keys enabled, Unity uses a generic ANSI/ISO “Qwerty” layout to represent the physical location of the keys regardless of the user’s actual layout. This means if you specify the “Q” key, it will always be the left-most letter on the first row of letter keys, even if the user’s keyboard has a different letter in that position.
Note, you should not read key input for in-game text input, because this will not allow users to enter non-Latin characters. Instead, use Input.compositionString
.
Every Project you create has a number of input axes created by default. These axes enable you to use keyboard, mouse, and joystick input in your Project straight away.
To see more about these axes, open the Input Manager window, and click the arrow next to any axis name to expand its properties.
Each input axis has the following properties:
Property | Function |
---|---|
Name | Axis name. You can use this to access the axis from scripts. |
Descriptive Name, Descriptive Negative Name | These values are deprecated and do not work. Previously, they displayed for the user on the Rebind Controls screen at startup, but this screen has also been deprecated. |
Negative Button, Positive Button | The controls to push the axis in the negative and positive direction respectively. These can be keys on a keyboard, or buttons on a joystick or mouse. |
Alt Negative Button, Alt Positive Button | Alternative controls to push the axis in the negative and positive direction respectively. |
Gravity | Speed in units per second that the axis falls toward neutral when no input is present. |
Dead | How far the user needs to move an analog stick before your application registers the movement. At runtime, input from all analog devices that falls within this range will be considered null. |
Sensitivity | Speed in units per second that the axis will move toward the target value. This is for digital devices only. |
Snap | If enabled, the axis value will reset to zero when pressing a button that corresponds to the opposite direction. |
Type | The type of input that controls the axis. Select from these values: - Key or Mouse button - Mouse Movement - Joystick Axis |
Axis | The axis of a connected device that controls this axis. |
JoyNum | The connected Joystick that controls this axis. You can select a specific joystick, or query input from all joysticks. |
Axis values can be:
To add a virtual axis, increase the number in the Size field. This creates a new axis at the bottom of the list. The new axis copies the properties of the previous axis in the list.
To remove a virtual axis, you can either:
To copy a virtual axis, right-click it and select Duplicate Array Element.
To map a key or button to an axis, enter its name in the Positive Button or Negative Button property in the Input Manager.
Key names follow these naming conventions:
Key family | Naming convention |
---|---|
Letter keys |
a , b , c … |
Number keys |
1 , 2 , 3 … |
Arrow keys |
up , down , left , right
|
Numpad keys |
[1] , [2] , [3] , [+] , [equals] … |
Modifier keys |
right shift , left shift , right ctrl , left ctrl , right alt , left alt , right cmd , left cmd
|
Special keys |
backspace , tab , return , escape , space , delete , enter , insert , home , end , page up , page down
|
Function keys |
f1 , f2 , f3 … |
Mouse buttons are named mouse 0, mouse 1, mouse 2,
and so on.
Joystick buttons follow these naming conventions:
Button origin | Naming convention |
---|---|
A specific button on any joystick |
joystick button 0 , joystick button 1 , joystick button 2 … |
A specific button on a specific joystick |
joystick 1 button 0 , joystick 1 button 1 , joystick 2 button 0 … |
You can also query input for a specific key or button with Input.GetKey
and the naming conventions specified above. For example:
Input.GetKey("a");
Another way to access keys is to use the KeyCode
enumeration.
To access virtual axes from scripts, you can use the axis name.
For example, to query the current value of the Horizontal axis and store it in a variable, you can use Input.GetAxis
like this:
float horizontalInput = Input.GetAxis ("Horizontal");
For axes that describe an event rather than a movement (for example, firing a weapon in a game), use Input.GetButtonDown
instead.
If two or more axes have the same name, the query returns the axis with the largest absolute value. This makes it possible to assign more than one input device to an axis name.
For example, you can create two axes named Horizontal and assign one to keyboard input and the other to joystick input. If the user is using the joystick, input comes from the joystick and keyboard input is null. Otherwise, input comes from the keyboard and joystick input is null. This enables you to write a single script that covers input from multiple controllers.
Example
You can use input from the Horizontal and Vertical axes and the transform.Translate
method to move a GameObjectThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary in XZ space (forward, back, left, or right). Add the following code to the update()
method on a script attached to the GameObject you want to move:
float moveSpeed = 10; //Define the speed at which the object moves. float horizontalInput = Input.GetAxis("Horizontal"); //Get the value of the Horizontal input axis. float verticalInput = Input.GetAxis("Vertical"); //Get the value of the Vertical input axis. transform.Translate(new Vector3(horizontalInput, verticalInput, 0) * moveSpeed * Time.deltaTime); //Move the object to XYZ coordinates defined as horizontalInput, 0, and verticalInput respectively.
Time.deltaTime
represents the time that passed since the last frame. Multiplying the moveSpeed
variable by Time.deltaTime
ensures that the GameObject moves at a constant speed every frame.
InputManager
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising. Some 3rd party video providers do not allow video views without targeting cookies. If you are experiencing difficulty viewing a video, you will need to set your cookie preferences for targeting to yes if you wish to view videos from these providers. Unity does not control this.
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.