04/25/15, 02:18 PM | #1 |
|
Understanding Keypress events
I've been trying to understand how to use keypress events correctly. Basically I want to toggle between first person view and third person view (then add a condition that if in 3rd person to enable middle mouse/freelook). I don't really have any code written up, just doing some basic testing with CHAT_SYSTEM:AddMessage('string') to see if it runs.
Currently, from what I can tell, keypress events seem to only be used for when a window is created (like making a custom options window for your addon). Is there a way to call for keypress events without having to use a window? Or use an event that is constantly on so that a keypress event can be detected? Not sure how to word things as I am new to coding and addon making (I've been looking through the forums and wiki and feel like I the functions I try to use are incorrect). lua Code:
ZO_CreateStringId('SI_BINDING_NAME_TOGGLE_CAM', 'TOGGLE CAMERA') local function ToggleCam() if key == KEY_V then CHAT_SYSTEM:AddMessage('Key press on V') end end Code:
<Bindings> <Layer name='SI_KEYBINDINGS_LAYER_GENERAL'> <Category name='Camera'> <Action name='TOGGLE_CAM'> <Down>ToggleCam()</Down> </Action> </Category> </Layer> </Bindings> |
04/25/15, 02:47 PM | #2 |
Keybindings can also be used without any window or even without any other control (label, texture, button, ...).
In your XML file just use Code:
<Layer name="SI_KEYBINDINGS_CATEGORY_GENERAL"> The keybinding will be usable inside the game's controls then and you designed it to be at "Camera" settings. You will find it with the text that you have defined as 2nd parameter in function ZO_CreateStringId(..., 'TOGGLE CAMERA'). So you can use your key "V" here to assign it to this keybinding in the ESO controls. If you press that key at the normal ESO ingame content (in your inventory, at the normal UI as you play and fight, etc.) the functionr egistered to this keybind will be executed. But for your lua source code be carefull: You defined a "local" function ToggleCam() but you have to define it global so the XML file will be able to use it too. XML file and lua source code are different files so they don't know each other if stuff is designed locally. Try to remove the "local" in front of function and you should be able to call the function from an XML file, or by using it inside the chat by help of the /script command: Code:
/script ToggleCam() Edit: About your function's content: Lua Code:
Last edited by Baertram : 04/25/15 at 02:55 PM. |
|
04/25/15, 03:09 PM | #3 | |
|
Thank you soooo much, this did the trick |
|
ESOUI » Developer Discussions » Lua/XML Help » Understanding Keypress events |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|