IsKeyDown

Constructor:

IsKeyDown(KeyCode)

Description

Returns whether the given key is pressed or not.

Parameters

Variable name Type Default Description
KeyCode string Character that identifies the key input from the keyboard

Return Value

Variable name Type Default Description
bool It is pressed or not

Examples

Keep monitoring in the loop whether the key is pressed or not. Print True if the key is found to be pressed, otherwise print False

coroutine.start(function()
    while true do
        coroutine.wait(0.01)        
        print(tostring(UserInputService.IsKeyDown(UnityEngine.KeyCode.Q)))
    end
end)
-- Notes: There are often some times not working out of 10 presses