WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   How to captur up & dpwn key presses and propagate events? (https://www.wowinterface.com/forums/showthread.php?t=54909)

alikim 12-10-16 03:45 AM

How to captur up & dpwn key presses and propagate events?
 
I have my own frame for events and if I write this code:

Code:

eframe:SetScript("OnKeyDown", eframe.OnKeyDown)
eframe:SetScript("OnKeyUp", eframe.OnKeyUp)
eframe:SetPropagateKeyboardInput(true)

then I don't capture Up event in my function, only Down.

I need to be able to capture both Down and Up events in my handlers and also propagate both events to the WorldFrame for the game to function normally.

Is there a way to do that?

Thanks!

SDPhantom 12-10-16 05:16 AM

The up handler doesn't fire when you propagate keyboard events. Running the bindings yourself is a protected action, so you can't go that route either.
One thing you might be able to do is register keybinds to issue a click to a button. See SetOverrideBindingClick(). I don't think it can differentiate up and down states.

If you mentioned what you're trying to implement, we may provide suggestions for other methods that may work instead.

alikim 12-10-16 09:16 AM

Quote:

Originally Posted by SDPhantom (Post 321251)
The up handler doesn't fire when you propagate keyboard events. Running the bindings yourself is a protected action, so you can't go that route either.
One thing you might be able to do is register keybinds to issue a click to a button. See SetOverrideBindingClick(). I don't think it can differentiate up and down states.

If you mentioned what you're trying to implement, we may provide suggestions for other methods that may work instead.

Thank you, I implemented my own loot window that unregisters LootFrame from all events and normally when you click on a loot it then autoloots items following some pattern and then does CloseLoot(). What I also want it to do is if I CTRL-click on loot it would list all loot items and let me loot individually but then when I release CTRL it should CloseLoot().

If it's hard to implement, I can ofc just capture Down event and move when I'm done looting, I guess that will CloseLoot() as well but I wanted to press a button to let the addon know that I want manual loot and then release that button to let it know that it can CloseLoot().

p3lim 12-10-16 01:52 PM

You mean ctrl-clicking the mob in the world?
Anyways, just use the normal loot event LOOT_OPENED and check for IsControlKeyDown(), which when pressed/depressed triggers MODIFIER_STATE_CHANGED.
To prevent default auto-looting, use the ctrl key as the modifier to avoid autolooting.

Something like this perhaps:
Lua Code:
  1. local Frame = CreateFrame('Frame')
  2. Frame:RegisterEvent('LOOT_OPENED')
  3. Frame:SetScript('OnEvent', function(self, event, arg1, arg2)
  4.     if(event == 'MODIFIER_STATE_CHANGED') then
  5.         if((arg1 == 'LCTRL' or arg1 == 'RCTRL') and not arg2) then
  6.             -- loot everything
  7.             arg1 = true
  8.             self:UnregisterEvent(event)
  9.         else
  10.             return
  11.         end
  12.     end
  13.  
  14.     if(arg1 and not IsControlKeyDown()) then
  15.         LootFrame_InitAutoLootTable(LootFrame)
  16.         LootFrame:SetScript('OnUpdate', LootFrame_OnUpdate)
  17.         LootFrame.AutoLootDelay = LOOTFRAME_AUTOLOOT_DELAY
  18.     else
  19.         LootFrame.AutoLootDelay = 0
  20.         LootFrame.AutoLootTable = nil
  21.         self:RegisterEvent('MODIFIER_STATE_CHANGED')
  22.     end
  23.  
  24.     LootFrame.page = 1
  25.     LootFrame_Show(LootFrame)
  26.  
  27.     if(not LootFrame:IsShown()) then
  28.         CloseLoot(not arg1 or IsControlKeyDown())
  29.     end
  30. end)


All times are GMT -6. The time now is 01:51 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI