OnClientKey: Difference between revisions
Jump to navigation
Jump to search
Line 7: | Line 7: | ||
<syntaxhighlight lang="lua">string button, bool pressOrRelease | <syntaxhighlight lang="lua">string button, bool pressOrRelease | ||
</syntaxhighlight> | </syntaxhighlight> | ||
* '''button''': This refers the button pressed. see [[https://wiki.multitheftauto.com/wiki/Key_names]] for list of keys | * '''button''': This refers the button pressed. see [[https://wiki.multitheftauto.com/wiki/Key_names]] for list of keys string | ||
* '''pressOrRelease''': This refers to whether they were pressing or releasing the key, true when pressing, false when releasing. | * '''pressOrRelease''': This refers to whether they were pressing or releasing the key, true when pressing, false when releasing. | ||
Revision as of 16:09, 28 August 2014
This event triggers whenever the user presses a button on their keyboard. This event can also be used to see if the client scrolls his mousewheel.
Parameters
string button, bool pressOrRelease
- button: This refers the button pressed. see [[1]] for list of keys string
- pressOrRelease: This refers to whether they were pressing or releasing the key, true when pressing, false when releasing.
Source
The source of this event is the client's root element.
Cancel effect
Example
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)
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 end return false end )
See Also
GUI events
Input
GUI
- onClientGUIAccepted
- onClientGUIBlur
- onClientGUIChanged
- onClientGUIClick
- onClientGUIComboBoxAccepted
- onClientGUIDoubleClick
- onClientGUIFocus
- onClientGUIMouseDown
- onClientGUIMouseUp
- onClientGUIMove
- onClientGUIScroll
- onClientGUISize
- onClientGUITabSwitched
- onClientMouseEnter
- onClientMouseLeave
- onClientMouseMove
- onClientMouseWheel
Client event functions
- triggerLatentServerEvent
- triggerServerEvent
- Shared
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled