Skip to content

Events & Keyboard Controls

Learn how to run code continuously and detect player keyboard presses.


Mod Callbacks (Events)

onTick()

The onTick() function is the heart of your mod. GTA IV calls it every single frame (around 60 times per second).

This is where you should check for key presses, draw HUD elements, or update game values:

function onTick()
    -- This code runs constantly while playing
end

onUnload()

Called when your mod is stopped or reloaded. Use it to clean up objects, delete spawned cars, or save settings:

function onUnload()
    log("Mod stopped!")
end

Detecting Keyboard Keys (is_key_down)

To check if a key is pressed, use is_key_down(key_code).

function onTick()
    if is_key_down(0x73) then -- F4
        log("F4 was pressed!")
    end
end

Common Keyboard Key Codes Reference

Here are the most useful Windows Virtual-Key (VK) codes to copy and paste:

Key Hex Code Decimal Description
F1 0x70 112 Function Key 1
F2 0x71 113 Function Key 2
F3 0x72 114 Function Key 3
F4 0x73 115 Function Key 4 (Trainer standard)
F5 0x74 116 Function Key 5
F6 0x75 117 Reserved (Built-in In-Game Editor)
F7 0x76 118 Function Key 7
F8 0x77 119 Function Key 8
F9 0x78 120 Function Key 9
Shift 0x10 16 Left or Right Shift
Ctrl 0x11 17 Left or Right Control
Alt 0x12 18 Alt Key
Space 0x20 32 Spacebar
Enter 0x0D 13 Return / Enter
Escape 0x1B 27 Escape
Tab 0x09 9 Tab Key
Arrow Up 0x26 38 Up Arrow
Arrow Down 0x28 40 Down Arrow
Arrow Left 0x25 37 Left Arrow
Arrow Right 0x27 39 Right Arrow
E Key 0x45 69 Letter E
T Key 0x54 84 Letter T
X Key 0x58 88 Letter X
Z Key 0x5A 90 Letter Z
0 to 9 0x30 - 0x39 48 - 57 Top number row (0-9)
Numpad 0-9 0x60 - 0x69 96 - 105 Numeric Keypad