Skip to main content

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 to 0, which is the keyboard.

Return Values

  • justPressed: boolean - Returns true if the key was just pressed, otherwise false.

Versions

  • DSL4 - DirectInput keyboard scan codes are now used, but virtual key code names will still be converted for legacy support.
  • DSL6 - The optional controller argument 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