GetFunctionsBoundToKey: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: __NOTOC__ {{Server function}} Gets the functions bound to a key. To bind a function to a key use the bindKey function ==Syntax== <syntaxhighlight lang="lua"> string getFunctionsBoundToKey ( player th...)
 
mNo edit summary
 
(12 intermediate revisions by 5 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Server function}}
{{Server client function}}
 
Gets the functions bound to a key. To bind a function to a key use the [[bindKey]] function
Gets the functions bound to a key. To bind a function to a key use the [[bindKey]] function


==Syntax==  
==Syntax==
<section name="Server" class="server" show="true" >
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
string getFunctionsBoundToKey ( player thePlayer, string theKey )
table getFunctionsBoundToKey ( player thePlayer, string key, string keyState )
</syntaxhighlight>
</syntaxhighlight>


Line 11: Line 13:
*'''thePlayer:''' The player to get the functions from a key.
*'''thePlayer:''' The player to get the functions from a key.
*'''theKey:''' The key you wish to check the functions from.
*'''theKey:''' The key you wish to check the functions from.
*'''keyState:''' A string that has one of the following values:
**'''"up":''' If the bound key should trigger the function when the key is released
**'''"down":''' If the bound key should trigger the function when the key is pressed
**'''"both":''' If the bound key should trigger the function when the key is pressed or released
</section>
<section name="Client" class="client" show="true" >
<syntaxhighlight lang="lua">
table getFunctionsBoundToKey ( string key, string keyState )
</syntaxhighlight>
===Required Arguments===
*'''theKey:''' The key you wish to check the functions from.
*'''keyState:''' A string that has one of the following values:
**'''"up":''' If the bound key should trigger the function when the key is released
**'''"down":''' If the bound key should trigger the function when the key is pressed
**'''"both":''' If the bound key should trigger the function when the key is pressed or released
</section>


===Returns===
===Returns===
Returns a string of the functions bound on that key.
Returns a table of the key function(s).


==Example==  
==Example==  
<section name="Client" class="client" show="true" >
This loops through all the keys and outputs the keyname and the function bound to that key.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--Example here
 
local keyTable = { "mouse1", "mouse2", "mouse3", "mouse4", "mouse5", "mouse_wheel_up", "mouse_wheel_down", "arrow_l", "arrow_u",
"arrow_r", "arrow_d", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "num_0", "num_1", "num_2", "num_3", "num_4", "num_5",
"num_6", "num_7", "num_8", "num_9", "num_mul", "num_add", "num_sep", "num_sub", "num_div", "num_dec", "F1", "F2", "F3", "F4", "F5",
"F6", "F7", "F8", "F9", "F10", "F11", "F12", "backspace", "tab", "lalt", "ralt", "enter", "space", "pgup", "pgdn", "end", "home",
"insert", "delete", "lshift", "rshift", "lctrl", "rctrl", "[", "]", "pause", "capslock", "scroll", ";", ",", "-", ".", "/", "#", "\\", "=" }
 
addCommandHandler("gakf",function()
for _,i in ipairs(keyTable)do --loop through keyTable
for _,v in ipairs(getFunctionsBoundToKey(i))do --loop through the key bounded functions
outputChatBox(i..":"..tostring(v)) --output the keyname and the function bound to it
end
end
end)
</syntaxhighlight>
</section>
<section name="Server" class="server" >
This loops through all the keys and outputs the keyname and the function bound to that key.
<syntaxhighlight lang="lua">
function output()
outputChatBox("Hi")
end
bindKey(root,"f2","down",output)
local keyTable = { "mouse1", "mouse2", "mouse3", "mouse4", "mouse5", "mouse_wheel_up", "mouse_wheel_down", "arrow_l", "arrow_u",
"arrow_r", "arrow_d", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "num_0", "num_1", "num_2", "num_3", "num_4", "num_5",
"num_6", "num_7", "num_8", "num_9", "num_mul", "num_add", "num_sep", "num_sub", "num_div", "num_dec", "F1", "F2", "F3", "F4", "F5",
"F6", "F7", "F8", "F9", "F10", "F11", "F12", "backspace", "tab", "lalt", "ralt", "enter", "space", "pgup", "pgdn", "end", "home",
"insert", "delete", "lshift", "rshift", "lctrl", "rctrl", "[", "]", "pause", "capslock", "scroll", ";", ",", "-", ".", "/", "#", "\\", "=" }
 
addCommandHandler("gakf",function(source) --source is the player
for _,i in ipairs(keyTable)do --loop through keyTable
for _,v in ipairs(getFunctionsBoundToKey(source,i))do --loop through the key bounded functions
outputChatBox(i..":"..v,source) --output the keyname and the function bound to it
end
end
end)
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Input_functions}}
{{Input_functions}}
[[Category:Needs_Example]]

Latest revision as of 15:10, 20 July 2018

Gets the functions bound to a key. To bind a function to a key use the bindKey function

Syntax

Click to collapse [-]
Server
table getFunctionsBoundToKey ( player thePlayer, string key, string keyState )

Required Arguments

  • thePlayer: The player to get the functions from a key.
  • theKey: The key you wish to check the functions from.
  • keyState: A string that has one of the following values:
    • "up": If the bound key should trigger the function when the key is released
    • "down": If the bound key should trigger the function when the key is pressed
    • "both": If the bound key should trigger the function when the key is pressed or released
Click to collapse [-]
Client
table getFunctionsBoundToKey ( string key, string keyState )

Required Arguments

  • theKey: The key you wish to check the functions from.
  • keyState: A string that has one of the following values:
    • "up": If the bound key should trigger the function when the key is released
    • "down": If the bound key should trigger the function when the key is pressed
    • "both": If the bound key should trigger the function when the key is pressed or released

Returns

Returns a table of the key function(s).

Example

Click to collapse [-]
Client

This loops through all the keys and outputs the keyname and the function bound to that key.


local keyTable = { "mouse1", "mouse2", "mouse3", "mouse4", "mouse5", "mouse_wheel_up", "mouse_wheel_down", "arrow_l", "arrow_u",
 "arrow_r", "arrow_d", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
 "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "num_0", "num_1", "num_2", "num_3", "num_4", "num_5",
 "num_6", "num_7", "num_8", "num_9", "num_mul", "num_add", "num_sep", "num_sub", "num_div", "num_dec", "F1", "F2", "F3", "F4", "F5",
 "F6", "F7", "F8", "F9", "F10", "F11", "F12", "backspace", "tab", "lalt", "ralt", "enter", "space", "pgup", "pgdn", "end", "home",
 "insert", "delete", "lshift", "rshift", "lctrl", "rctrl", "[", "]", "pause", "capslock", "scroll", ";", ",", "-", ".", "/", "#", "\\", "=" }

addCommandHandler("gakf",function()
	for _,i in ipairs(keyTable)do --loop through keyTable
		for _,v in ipairs(getFunctionsBoundToKey(i))do --loop through the key bounded functions
			outputChatBox(i..":"..tostring(v)) --output the keyname and the function bound to it
		end
	end
end)
Click to expand [+]
Server

See Also