From Multi Theft Auto: Wiki
Jump to: navigation, search

This event triggers whenever the user presses a button on their keyboard or mouse. This event can also be used to see if the client scrolls their mouse wheel.


string button, bool pressOrRelease
  • button: This refers the button pressed. See key names for a list of keys.
  • pressOrRelease: This refers to whether they were pressing or releasing the key, true when pressing, false when releasing.


The source of this event is the client's root element.

Cancel effect


If this event is canceled, then all GTA and MTA binds, bound to the canceled key, won't be triggered.

Note: the escape key can only be cancelled once. If a user presses the escape key twice in a row the main menu will still open.

Note: The event is only cancellable when the key is being pressed, not when being released.


This example will say in chatbox every time the user presses down a a key.

function playerPressedKey(button, press)
    if (press) then -- Only output when they press it down
        outputChatBox("You pressed the "..button.." key!")
addEventHandler("onClientKey", root, playerPressedKey)

This example outputs if the client moves his mousewheel.

addEventHandler( "onClientKey", root, function(button,press) 
    -- Since mouse_wheel_up and mouse_wheel_down cant return a release, we dont have to check the press.
    if button == "mouse_wheel_up" or button == "mouse_wheel_down" then
        outputDebugString( button .. " moved." )
        return true
    return false
end )

See Also

GUI events

Client event functions