onClientKey | Multi Theft Auto: Wiki Skip to content

onClientKey

Client-side
Server-side
Shared

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.

F8 key not triggered on this event!

Parameters

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.

Source

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

Canceling

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

Code Examples

client

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!")
end
end
addEventHandler("onClientKey", root, playerPressedKey)