Input Manager quick reference
The Input Manager script allows you to change keyboard mappings with scripting in Unity 3D. Below is a reference of the functions available and what they do. For a Quick start guide on getting started, check out my tutorial page.
Function | Description |
---|---|
bool setKeybind(string bindName, KeyCode newCode, bool setAlternate = false) or bool setKeybind(string bindName, KeyCode newCode, KeyCode altnewCode) |
Sets the bind's coresponding KeyCode value. With overloaded options to change the alternate keyCode as well. Returns false if the keyBind doesn't exist |
float GetAxis(string axisName) | Returns a value between -1.0 and +1.0 with smoothing. Joystick and other Axis types coming soon. |
float GetAxisRaw(string axisName) | Returns either -1.0, 0 or +1.0 without smoothing between. |
bool getInputDown(string keyName) | Returns true if the key corresponding to keyName is being pressed this frame. Returns direct readings from Unity's Input class. |
bool getInput(string keyName) | Returns true if the key corresponding to keyName went from being up to being pressed this frame. Returns direct readings from Unity's Input class. |
bool getInputUp(string keyName) | Returns true if the key corresponding to keyName has been release from being pressed this frame. Returns direct readings from Unity's Input class. |
bool GetKey(string keyName) | Returns true if the key corresponding to keyName is being pressed this frame. Returns values recorded on a frame by frame basis. |
bool GetKeyDown(string keyName) | Returns true if the key corresponding to keyName went from being up to being pressed this frame. Returns values recorded on a frame by frame basis. |
bool GetKeyUp(string keyName) | Returns true if the key corresponding to keyName has been release from being pressed this frame. Returns values recorded on a frame by frame basis. |
keyBind[] getDuplicateBinds() | Returns an array containing all the KeyBinds that are referencing the same KeyCodes. Does not include keyBinds whose Alternate keys are identical because they're set to KeyCode.None |
keyBind[] getUnboundKeys(bool includeAlts) | Returns an array containing all the KeyBinds bound to KeyCode.None. Option to include alternateKeys. |
IEnumerator WaitForKeyPress(float timeout = 0.0f) | Waits for next keyboard or mouse button to be pressed and then ends the coroutine. Will end after timeout seconds pass only if a value is passed, otherwise the coroutine will go on forever until a button is pressed. Return values are stored in InputManager.lastKeyPressed and will return KeyCode.None on timeouts Note: The InputManager script must be enabled for this coroutine to operate properly. |
Vector3 mousePosition | Property that returns Input.mousePosition on get and allows you move the mouse cursor through scripting to any point on the screen.
For instance; InputManager.mousePosition=new Vector3(Screen.width/2, Screen.height/2, 0 ); Will move the mouse to the center of the Unity window |
Rect MouseClip | Property that allows you to constrain the mouse cursor to a certain area of the screen. Returns the current clipping Rect on get. For instance; InputManager.MouseClip = new Rect(0, 0, Screen.width, Screen.height); Will keep the mouse inside the Unity window. |
void resetMouseClip() | Frees the mouse from any previosly assigned constraints |
void loadKeyBindsPref() | Loads keyBind information from player preferences. |
void saveKeyBindsPref() | Saves keyBind information into player preferences. |