Difference between revisions of "ScriptHook.RegisterKeyHandler"
From Nomad DB
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | Registers a Lua callback to a [[ | + | Registers a Lua callback to a [[ScriptHook: Key Binds|Key Bind]]. The Key Bind has to be registered inside [[ScriptHook: manifest.json|manifest.json]] first. |
'''SimpleMenu''' | '''SimpleMenu''' | ||
− | You can use [[UI.SimpleMenu]] to create custom Menus for your [[ | + | You can use [[UI.SimpleMenu]] to create custom Menus for your [[ScriptHook: Script|Script]], which you can bind to a key handler. See [[UISimpleMenu:Toggle]] or the example below for more information. |
== Syntax == | == Syntax == | ||
Line 11: | Line 11: | ||
* '''name''' (string) Key bind name, must match ''manifest.json'' entry | * '''name''' (string) Key bind name, must match ''manifest.json'' entry | ||
* '''callback''' (function) Lua callback | * '''callback''' (function) Lua callback | ||
+ | |||
+ | '''Returns:''' | ||
+ | |||
+ | {{Warning|A return value is currently supported for Mafia DE ScriptHook version 1.1.2+}} | ||
+ | |||
+ | * '''keyName''' (string) Human-readable key name | ||
== Example == | == Example == | ||
Line 31: | Line 37: | ||
== Related Pages == | == Related Pages == | ||
− | * [[ | + | * [[ScriptHook: Key Binds]] and [[ScriptHook: manifest.json]] |
* [[UI.SimpleMenu]] | * [[UI.SimpleMenu]] | ||
− | [[Category: | + | [[Category:ScriptHook Lua]] |
Latest revision as of 20:13, 8 October 2021
Registers a Lua callback to a Key Bind. The Key Bind has to be registered inside manifest.json first.
SimpleMenu
You can use UI.SimpleMenu to create custom Menus for your Script, which you can bind to a key handler. See UISimpleMenu:Toggle or the example below for more information.
Syntax
ScriptHook.RegisterKeyHandler(name, callback)
- name (string) Key bind name, must match manifest.json entry
- callback (function) Lua callback
Returns:
A return value is currently supported for Mafia DE ScriptHook version 1.1.2+
- keyName (string) Human-readable key name
Example
The example below shows you how to a bind a custom Simple Menu toggle to a key handler. manifest.json (excerpt)
"keyBinds": {
"menu": "F5"
}
Code
local my_menu = UI.SimpleMenu()
-- ~~ menu code ~~ --
ScriptHook.RegisterKeyHandler("menu", function()
my_menu:Toggle()
end)