Difference between revisions of "ScriptHook: Key Binds"
From Nomad DB
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | A [[ | + | A [[ScriptHook: Script|Script]] can register Key bindings. |
− | == Registering a Key Bind == | + | ==Registering a Key Bind== |
− | To register a Key bind, use the [[ | + | To register a Key bind, use the [[ScriptHook: Script|Script]]'s [[ScriptHook: manifest.json|manifest.json]]. |
'''manifest.json''' | '''manifest.json''' | ||
Line 13: | Line 13: | ||
'''[[Key Codes|List of Key Codes]]''' | '''[[Key Codes|List of Key Codes]]''' | ||
− | == Key Handler == | + | ==Key Handler== |
Use [[ScriptHook.RegisterKeyHandler]] function. | Use [[ScriptHook.RegisterKeyHandler]] function. | ||
− | === Example === | + | ===Example=== |
Registers a callback function to a Key binding. In combination with the ''manifest.json'' above, this code would print "Key Bind" to the [[WD2 ScriptHook: Console|Console]] when pressing F5. | Registers a callback function to a Key binding. In combination with the ''manifest.json'' above, this code would print "Key Bind" to the [[WD2 ScriptHook: Console|Console]] when pressing F5. | ||
Line 22: | Line 22: | ||
ScriptHook.RegisterKeyHandler("test", function() | ScriptHook.RegisterKeyHandler("test", function() | ||
print("Key Bind") | print("Key Bind") | ||
− | + | end) | |
</syntaxhighlight> | </syntaxhighlight> | ||
− | == Related Pages == | + | ==Related Pages== |
− | |||
− | |||
− | |||
− | [[Category: | + | *[[ScriptHook]] |
+ | *[[ScriptHook: Script|manifest.json]] | ||
+ | *[[Key Codes]] | ||
+ | |||
+ | [[Category:ScriptHook]] |
Latest revision as of 12:29, 6 October 2020
A Script can register Key bindings.
Registering a Key Bind
To register a Key bind, use the Script's manifest.json.
manifest.json
"keyBinds": {
"test": "F5"
}
Key Handler
Use ScriptHook.RegisterKeyHandler function.
Example
Registers a callback function to a Key binding. In combination with the manifest.json above, this code would print "Key Bind" to the Console when pressing F5.
ScriptHook.RegisterKeyHandler("test", function()
print("Key Bind")
end)