Skip to content

IsControlJustPressed

Call a callback when a specific key was pressed, more optimized and easy to use

Argument Data Type Needed Default Description
Control string - The key, this is the list
Callback function - The code executed when the key was pressed
Description string -

Dont need to be called every frame


Example

Run at 0 ms

IsControlJustPressed("K", function()
    print("Hello")
end)

Curiosity

"Control" parameter also accepts I/O from MOUSE_BUTTON or PAD_DIGITALBUTTON mappers, it will automatically figure out if it is keyboard, mouse or pad

Old method

Run at 2/3 ms

Citizen.CreateThread(function()
    while true do
        if IsControlJustPressed(0, 311) then
            print("Hello")
        end
        Citizen.Wait(1)
    end
end)

IsControlJustPressed

although i dont recommend it, you can use the old native via old_IsControlJustPressed


Last update: October 31, 2022
Created: June 27, 2021