OnClientKey: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "{{Client event}} __NOTOC__ This event triggers whenever the user presses a button on their keyboard. ==Parameters== <syntaxhighlight lang="lua">string button, bool pressOrRelease </syntaxhighlight> * ''...")
 
No edit summary
Line 2: Line 2:
__NOTOC__  
__NOTOC__  
This event triggers whenever the user presses a button on their keyboard.
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==
==Parameters==
Line 20: Line 21:
end
end
addEventHandler("onClientKey", root, playerPressedKey)
addEventHandler("onClientKey", root, playerPressedKey)
</syntaxhighlight>
This example outputs if the client moves his mousewheel.
<syntaxhighlight lang="lua">
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 )
</syntaxhighlight>
</syntaxhighlight>



Revision as of 10:50, 28 April 2013

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.
  • 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.

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


Client event functions