Input¶
Static Class
This object is a static class. It can be accessed by using its name as a keyword like this: Input
.
Additionally, it cannot be created in the creator menu or with Instance.New()
.
Input is a class used for retrieving user input data, such as the mouse and keyboard.
Events¶
KeyDown¶
Parameters: key [ string
]
Fires when a key is pressed.
Example
Input.KeyDown:Connect(function (key)
print(key .. " was pressed!")
if key == "P" then
print("The 'P' key was pressed!")
end
end)
KeyUp¶
Parameters: key [ string
]
Fires when a key is released.
Input.KeyUp:Connect(function (key)
print(key .. " was pressed!")
if key == "P" then
print("The 'P' key was pressed!")
end
end)
Methods¶
Undocumented Methods
This section is a work in progress! The methods GetMouseWorldPoint
, and GetMouseWorldPosition
, are not written yet. Want to contribute? Go to the GitHub and open a pull request here!
GetAxis → float
¶
Parameters: axisName [ string
]
Returns the value of the specified axis.
GetAxisRaw → float
¶
Parameters: axisName [ string
]
Returns the value of the specified axis without smoothing filtering.
GetButton → boolean
¶
Parameters: buttonName [ string
]
Returns true
if the specified button is being held down.
GetButtonDown → boolean
¶
Parameters: buttonName [ string
]
Returns true
during the frame in which the specified button was pressed.
GetButtonUp → boolean
¶
Parameters: buttonName [ string
]
Returns true
during the frame in which the specified button was released.
GetKey → boolean
¶
Parameters: keyName [ string
]
Returns true
if the specified key is being held down.
GetKeyDown → boolean
¶
Parameters: keyName [ string
]
Returns true
during the frame in which the specified key was pressed.
GetKeyUp → boolean
¶
Parameters: keyName [ string
]
Returns true
during the frame in which the specified key was released.
GetMouseButton → boolean
¶
Parameters: mouseButton [ int
]
Returns true
if the specified mouse button is being held down.
GetMouseButtonDown → boolean
¶
Parameters: mouseButton [ int
]
Returns true
during the frame in which the specified mouse button was pressed.
GetMouseButtonUp → boolean
¶
Parameters: mouseButton [ int
]
Returns true
during the frame in which the specified mouse button was released.
ScreenPointToRay → RayResult¶
Cast a ray from the camera at screen point into the game world
ViewportPointToRay → RayResult¶
Cast a ray from the camera at the specified ViewportPoint (Vector3 with components with values in range of 0 - 1 describing how far a point is to to right and to the top of the screen) into the game world
ScreenToViewportPoint → Vector3¶
Parameters: screenPosition [ Vector3 ]
Transforms screenPosition
parameter from screen space into viewport space.
ScreenToWorldPoint → Vector3¶
Parameters: screenPosition [ Vector2 ]
Transforms screenPosition
from screen space into world space.
World space coordinates can still be calculated even when provided as an off-screen coordinate.
ViewportToScreenPoint → Vector3¶
Parameters: viewportPosition [ Vector2 ]
Transforms viewportPosition
from viewport space into screen space.
ViewportToWorldPoint → Vector3¶
Parameters: viewportPosition [ Vector2 ]
Transforms viewportPosition
from viewport space into world space.
ViewportToWorldPoint transforms an x-y screen position into a x-y-z position in 3D space.
WorldToScreenPoint → Vector3¶
Parameters: worldPosition [ Vector3 ]
Transforms worldPosition
from world space into screen space.
WorldToViewportPoint → Vector3¶
Parameters: worldPosition [ Vector3 ]
Transforms worldPosition
from world space into viewport space.
Properties¶
AnyKey : boolean
¶
Returns true
if any key is being pressed.
AnyKeyDown : boolean
¶
Returns true
if any new key presses happened during the current frame. Held down key presses from previous frames do not count.
MousePosition : Vector2¶
Returns the current mouse position.
CursorLocked : boolean
¶
Determines whether or not the cursor is locked.
Example
Input.CursorLocked = true
CursorVisible : boolean
¶
Determines whether or not the cursor is visible.
Example
Input.CursorVisible = true