Difference between revisions of "ScriptHook.RegisterKeyHandler"
From Nomad DB
(Created page with "Registers a Lua callback to a Key Bind. The Key Bind has to be registered inside manifest.json first. == Synta...") |
|||
Line 1: | Line 1: | ||
Registers a Lua callback to a [[WD2 ScriptHook: Key Binds|Key Bind]]. The Key Bind has to be registered inside [[WD2 ScriptHook: manifest.json|manifest.json]] first. | Registers a Lua callback to a [[WD2 ScriptHook: Key Binds|Key Bind]]. The Key Bind has to be registered inside [[WD2 ScriptHook: manifest.json|manifest.json]] first. | ||
+ | |||
+ | '''SimpleMenu''' | ||
+ | |||
+ | You can use [[UI.SimpleMenu]] to create custom Menus for your [[WD2 ScriptHook: Script|Script]], which you can bind to a key handler. See [[UISimpleMenu:Toggle]] for more information. | ||
== Syntax == | == Syntax == |
Revision as of 22:51, 16 April 2020
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 for more information.
Syntax
ScriptHook.RegisterKeyHandler(name, callback)
- name (string) Key bind name, must match manifest.json entry
- callback (function) Lua callback
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)