Thread Tools Display Modes
05/25/15, 12:04 PM   #1
JohnnyKing94
 
JohnnyKing94's Avatar
Join Date: Mar 2015
Posts: 45
Onkeydown handler

I want to know why with with the handler onkeydown there is no such propagation of the other binding events when i click any other keys that is not the "A" key??? what am i doing wrong?


Code:
MyPanel:SetHandler("OnKeyDown", function(self, key, ctrl, alt, shift, command) 
   if( key =="A")
      RUNNING NEXT LEVEL
   end
end)
  Reply With Quote
05/25/15, 12:16 PM   #2
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
Originally Posted by JohnnyKing94 View Post
I want to know why with with the handler onkeydown there is no such propagation of the other binding events when i click any other keys that is not the "A" key??? what am i doing wrong?


Code:
MyPanel:SetHandler("OnKeyDown", function(self, key, ctrl, alt, shift, command) 
   if( key =="A")
      RUNNING NEXT LEVEL
   end
end)
http://wiki.esoui.com/Globals#KeyCode

Lua Code:
  1. if( key == KEY_A )
  Reply With Quote
05/25/15, 12:31 PM   #3
JohnnyKing94
 
JohnnyKing94's Avatar
Join Date: Mar 2015
Posts: 45
Originally Posted by Ayantir View Post
http://wiki.esoui.com/Globals#KeyCode

Lua Code:
  1. if( key == KEY_A )
but i don't want the keycode... what i want to say is to prevent a single bind_key from being pushed but allowing all others (since for crown store i can have A,B,C,D etc), example

Code:
if( key == "INTERCEPT_TOGGLE_MARKET" )
  Reply With Quote
05/25/15, 01:12 PM   #4
Rarder44
Join Date: May 2015
Posts: 1
Ayantir i think JohnnyKing94 would know how to propagate the key get to the "main game"
Example:
my key I is keybinded with Inventory
If i click I, the OnKeyDown Handle catch that key and the inventory does not open.
So, i think he try to propagate the key given by the "function(self, key, ctrl, alt, shift, command)" to the """"Top Level Game""""

sorry JohnnyKing94, but i don't know the answer
  Reply With Quote
05/25/15, 11:54 PM   #5
JohnnyKing94
 
JohnnyKing94's Avatar
Join Date: Mar 2015
Posts: 45
Stiil anyone got the solution?? thx in advance
  Reply With Quote
05/26/15, 08:24 AM   #6
ZOS_ChipHilseberg
ZOS Staff!
Premium Member
Yes this person is from ZeniMax!
Join Date: Oct 2014
Posts: 551
There's no way I can think of to do this with the existing code. However, we might be able to change the OnKeyDown, OnKeyUp and OnChar handlers to continue propagating the key if false is returned from the handler. Would that allow you to do what you're trying to do?
  Reply With Quote
05/26/15, 01:29 PM   #7
JohnnyKing94
 
JohnnyKing94's Avatar
Join Date: Mar 2015
Posts: 45
Originally Posted by ZOS_ChipHilseberg View Post
There's no way I can think of to do this with the existing code. However, we might be able to change the OnKeyDown, OnKeyUp and OnChar handlers to continue propagating the key if false is returned from the handler. Would that allow you to do what you're trying to do?
Yes, it would be a wonderful idea... since that's what i'm trying to do... anyway if you're going try to do that, do i need to wait something, like a patch/hotfix or what?? Thx in advance
  Reply With Quote
05/26/15, 04:42 PM   #8
ZOS_ChipHilseberg
ZOS Staff!
Premium Member
Yes this person is from ZeniMax!
Join Date: Oct 2014
Posts: 551
What application do you plan to use this for?
  Reply With Quote
05/28/15, 09:24 AM   #9
JohnnyKing94
 
JohnnyKing94's Avatar
Join Date: Mar 2015
Posts: 45
Originally Posted by ZOS_ChipHilseberg View Post
What application do you plan to use this for?
I am creating some scenes via LibMainMenu (addon) where I need KeyboardEnabled... I am going to execute some of these buttons through SetHandler("OnKeyDown") or to block or to run them on the next level... so basically the return false is fine...
  Reply With Quote
05/28/15, 01:11 PM   #10
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
Can't you use Keybind strip ?
  Reply With Quote
05/28/15, 01:45 PM   #11
JohnnyKing94
 
JohnnyKing94's Avatar
Join Date: Mar 2015
Posts: 45
Originally Posted by Ayantir View Post
Can't you use Keybind strip ?
I already tried in the past to use the ZO_KeybindStrip without having good results due to the lack of explainations on the wiki page and the missing knowledge on how to apply it correctly... if you have a good example of working code, you're just amazing... thx in advance
  Reply With Quote
05/28/15, 05:15 PM   #12
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
Originally Posted by JohnnyKing94 View Post
I already tried in the past to use the ZO_KeybindStrip without having good results due to the lack of explainations on the wiki page and the missing knowledge on how to apply it correctly... if you have a good example of working code, you're just amazing... thx in advance
  • When addon loads, you'll need to declare the descriptor.
  • When you show your panel, you'll need to add your keybind strip
  • When you hide your panel, you'll need to remove it.



When addon loads, you'll need to declare the descriptor.
Lua Code:
  1. myaddon.keybindDescriptor = {
  2.     alignment = KEYBIND_STRIP_ALIGN_CENTER,
  3.     {
  4.         name = GetString(A_STRING_CREATED_WITH_ZO_CREATESTRINGID),
  5.         keybind = "UI_SHORTCUT_PRIMARY", -- or any other bindings. to create a binding, you'll need to write a small piece of xml and define it. but you can use standardui keybinds too.
  6.         control = self, -- don't change
  7.         callback = function(descriptor)
  8.             --function to execute when you'll click / push the keybind button.
  9.         end,
  10.         visible = function(descriptor)
  11.             -- returns a boolean to say if keybind is visible or not.
  12.         end
  13.     },





When you show your panel, you'll need to add your keybind strip
When you hide your panel, you'll need to remove it.
Lua Code:
  1. local function showOrHide(oldState, newState)
  2.    
  3.     if newState == SCENE_SHOWING then
  4.         KEYBIND_STRIP:AddKeybindButtonGroup(myaddon.keybindDescriptor)
  5.     elseif newState == SCENE_HIDDEN then
  6.         if KEYBIND_STRIP:HasKeybindButtonGroup(myaddon.keybindDescriptor) then
  7.             KEYBIND_STRIP:RemoveKeybindButtonGroup(myaddon.keybindDescriptor)
  8.         end
  9.     end
  10.    
  11. end
  12.  
  13. myAddon.sceneWithKeybind = SCENE_MANAGER:GetScene("itsNameDefinedInSceneManager")
  14. myAddon.sceneWithKeybind:RegisterCallback("StateChange", showOrHide)




You can also update your keybind. Eg you hover your mouse over a control, and you need to update your keybind strip :
Lua Code:
  1. local function UpdateKeybind(control)
  2.    
  3.     if KEYBIND_STRIP:HasKeybindButtonGroup(pChat.autoMsgDescriptor) then
  4.         KEYBIND_STRIP:UpdateKeybindButtonGroup(pChat.autoMsgDescriptor)
  5.     end
  6.    
  7. end
  8.  
  9. ...
  10.  
  11. control:SetHandler("OnMouseEnter", function(self) UpdateKeybind(self) end)
  12. control:SetHandler("OnMouseExit", function(self) UpdateKeybind(self) end)



  Reply With Quote
05/29/15, 06:33 AM   #13
JohnnyKing94
 
JohnnyKing94's Avatar
Join Date: Mar 2015
Posts: 45
Thanks for the code, I will certainly use it...
Unfortunately this code allows me to set only "new" bindings attached to a specific specific scene, instead if i would try to link an existing binding, some of them need to be processed and propagated, while others (for different circumstances, like UI errors) need to be stopped from propagation

Code:
EXAMPLE:
in KEYBIND_STRIP I insert 2 binds to existing keybindings:
* -TOGGLE_INVENTORY
* -TOGGLE_CHARACTER
When it's pressed TOGGLE_INVENTORY, the callback function is called and the inventory is shown.
When it's pressed TOGGLE_CHARACTER, the callback function needs to be called without having the caracter display opened (The addon will not work properly in that way...), so basically I need to block the propagation (that's the stuff I can't do it)

Another small problem is that I should bind about 6-7 keys and they do not entirely fit in the KEYBIND_STRIP
  Reply With Quote
05/29/15, 07:39 AM   #14
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
Use buttons ?
Existing keybinds can also be rewrited if needed.

What kind of thing would you like to do? post a screen, give exemples, I'm sure we can give you some advices.
  Reply With Quote
05/30/15, 02:49 PM   #15
JohnnyKing94
 
JohnnyKing94's Avatar
Join Date: Mar 2015
Posts: 45
Originally Posted by Ayantir View Post
Use buttons ?
Existing keybinds can also be rewrited if needed.

What kind of thing would you like to do? post a screen, give exemples, I'm sure we can give you some advices.
This is a part of my code with some comments to explain the purpose and the meaning of my scene

Code:
MY.LMM = LibStub("LibMainMenu")
ZO_CreateStringId("SI_MY_STRING", "SCENE")

MY_MAIN_MENU_CATEGORY_DATA =
    {
  descriptor = 1,
        binding = "MY_SHOW_PANEL",
        categoryName = SI_MY_NOME_ADDON,
        normal = "EsoUI/Art/MainMenu/menuBar_champion_up.dds",
  pressed = "EsoUI/Art/MainMenu/menuBar_champion_down.dds",
  highlight = "EsoUI/Art/MainMenu/menuBar_champion_over.dds",
  callback = function() 
   MY.LMM:ToggleCategory(MY.MENU_CATEGORY_MY)
  end
    }
 
 MY_SCENE = ZO_Scene:New("MYScene", SCENE_MANAGER) 
    
 MY_SCENE:AddFragmentGroup(FRAGMENT_GROUP.MOUSE_DRIVEN_UI_WINDOW)
 MY_SCENE:AddFragmentGroup(FRAGMENT_GROUP.PLAYER_PROGRESS_BAR_KEYBOARD_CURRENT)
 MY_SCENE:AddFragment(TITLE_FRAGMENT)
 MY_SCENE:AddFragment(RIGHT_BG_FRAGMENT)
 MY_SCENE:AddFragment(TOP_BAR_FRAGMENT)
 
    MY_SCENE_TITLE_FRAGMENT = ZO_SetTitleFragment:New(SI_MY_STRING)
    MY_SCENE:AddFragment(MY_SCENE_TITLE_FRAGMENT)
 

    MY_SCENE_WINDOW = ZO_FadeSceneFragment:New(SCENE_XML)
    MY_SCENE:AddFragment(MY_SCENE_WINDOW)
    
 MY_MENU_BAR = ZO_FadeSceneFragment:New(ZO_MainMenuCategoryBar)
 MY_SCENE:AddFragment(MY_MENU_BAR)
 
  local iconData = {
    {
     categoryName = SI_MY_STRING, -- Titolo vicino ai bottoni
     descriptor = "MySceneDesc",
     normal = "EsoUI/art/mainmenu/menubar_social_up.dds",
     pressed = "EsoUI/art/mainmenu/menubar_social_down.dds",
     highlight = "EsoUI/art/mainmenu/menubar_social_over.dds",
    },
   
   }
   
   
   
 SCENE_MANAGER:AddSceneGroup("MySceneGroup", ZO_SceneGroup:New("MySceneDesc"))
 
 MY.MY_MENU_CATEGORY = MY.LMM:AddCategory(MY_MAIN_MENU_CATEGORY_DATA)

 MY.LMM:AddSceneGroup(MY.MY_MENU_CATEGORY, "MYSceneGroup", iconData)

 local LMMXML = WINDOW_MANAGER:CreateControl("LMMXML2", ZO_MainMenuCategoryBar, CT_BUTTON)
 LMMXML:SetAnchor(CENTER, ZO_MainMenuCategoryBar, nil, 0, 28)
 MY.categoryBar = CreateControlFromVirtual("$(parent)CategoryBar", LMMXML2, "ZO_MenuBarTemplate")
 MY.categoryBar:SetAnchor(RIGHT, ZO_MainMenuCategoryBarButton1, LEFT, -20, 0)
 
 
 local categoryBarData =
 {
  buttonPadding = 16,
  normalSize = 51,
  downSize = 64,
  animationDuration = DEFAULT_SCENE_TRANSITION_TIME,
  buttonTemplate = "ZO_MainMenuCategoryBarButton",
 }
 ZO_MenuBar_SetData(MY.categoryBar, categoryBarData)
 ZO_MenuBar_AddButton(MY.categoryBar, MY_MAIN_MENU_CATEGORY_DATA)
 
 SCENE_XML:SetKeyboardEnabled(true)
 -- I need this for catching the key
 
 SCENE_XML:SetHandler("OnKeyDown", function(self, key, ctrl, alt, shift, command) 
  
   -- Example
   if(key==KEY_A) then 
    -- do my work
   else
    -- do my work
    return false -- call the propagation of the key
    
   end
  end)
  Reply With Quote
06/01/15, 11:15 AM   #16
ZOS_ChipHilseberg
ZOS Staff!
Premium Member
Yes this person is from ZeniMax!
Join Date: Oct 2014
Posts: 551
Have you tried making a new keybind layer, binding A to your new action and pushing it on when your scene is showing? That way all the other keys will fall through naturally.
  Reply With Quote
06/03/15, 01:14 AM   #17
JohnnyKing94
 
JohnnyKing94's Avatar
Join Date: Mar 2015
Posts: 45
Originally Posted by ZOS_ChipHilseberg View Post
Have you tried making a new keybind layer, binding A to your new action and pushing it on when your scene is showing? That way all the other keys will fall through naturally.
What i asked was to intercept an existing keybinding... anyway if i make a keybind layer, can i assosiate an existing key already in use from another keybind?? If it is so, is it possible to make it from LUA without setting the keybind on the game??

Code:
Example
When my scene is opened, what i want is to block the propagation of an existing key and let the others propagate, example: my scene is opened, i want to block the Key J for the journal quest and let all the other keys propagate


if ( key==KEY_L )
    -- I call the functions of my addon
    -- I LET THE KEY PROPAGATES
else if ( key==KEY_P )
    -- I call the functions of my addon
    -- I DO NOT LET THE KEY PROPAGATES
    -- I close the scene
end if
I hope it is clear now, that's why i wanted the return false for the OnKeyDown and i'm still waiting

Last edited by JohnnyKing94 : 06/03/15 at 01:18 AM.
  Reply With Quote
06/03/15, 02:47 AM   #18
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
you can rewrite almost all of keybinds in game and set your own code triggers at their place, just backup the callback, and update the keybind.

which keybind do you want to overwrite ?
  Reply With Quote
06/03/15, 09:43 AM   #19
JohnnyKing94
 
JohnnyKing94's Avatar
Join Date: Mar 2015
Posts: 45
Originally Posted by Ayantir View Post
you can rewrite almost all of keybinds in game and set your own code triggers at their place, just backup the callback, and update the keybind.

which keybind do you want to overwrite ?
A keybind i want to overwrite is the Inventory... if you have a working code, i'll appreciate
  Reply With Quote
06/07/15, 03:18 AM   #20
JohnnyKing94
 
JohnnyKing94's Avatar
Join Date: Mar 2015
Posts: 45
Still nothing?? Pls guys I really need it
  Reply With Quote

ESOUI » AddOns » AddOn Help/Support » Onkeydown handler

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off