IsKeyBeingPressed
This function was added in DSL 1
Description
Check if a key was just pressed, meaning it is pressed this frame but was not on the previous one.
key and controller are interpreted the same way as they are by IsKeyPressed.
function IsKeyBeingPressed(key, controller) --[[ ... ]] end
Parameters
key:string- The name of the key to check.controller?:0|1|2|3- (Optional) The controller to check the key on. Defaults to0, which is the keyboard.
Return Values
justPressed:boolean- Returnstrueif the key was just pressed, otherwisefalse.
Versions
- DSL4 - DirectInput keyboard scan codes are now used, but virtual key code names will still be converted for legacy support.
- DSL6 - The optional
controllerargument was added.
Example
Check if the 'W' key was just pressed and print a message.
function main()
local key = 'W'
while true do
if IsKeyBeingPressed(key) then
DrawTextInline(key .. ' key was just pressed!', 0, 1)
end
Wait(0)
end
end
See Also
- DSL
IsKeyBeingReleased- Check if a key was just released.IsKeyPressed- Check if a key is being held down.IsKeyValid- Check if a key is valid.