Thread Tools Display Modes
12-10-16, 03:45 AM   #1
alikim
A Fallenroot Satyr
Join Date: Jul 2015
Posts: 27
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!
  Reply With Quote
12-10-16, 05:16 AM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
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.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 12-10-16 at 05:24 AM.
  Reply With Quote
12-10-16, 09:16 AM   #3
alikim
A Fallenroot Satyr
Join Date: Jul 2015
Posts: 27
Originally Posted by SDPhantom View Post
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().
  Reply With Quote
12-10-16, 01:52 PM   #4
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
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)

Last edited by p3lim : 12-10-16 at 02:06 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How to captur up & dpwn key presses and propagate events?


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