Quantcast
Record button presses. - WoWInterface
Thread Tools Display Modes
07-25-13, 11:55 PM   #1
Yksrep
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 21
Record button presses.

Is it possible to record button presses and then do something.
I mean something like

If
A button pressed and B button pressed
then
C button show.

#See Below for working Code. The easiest way to get it to work is
local button = CreateFrame("CheckButton", "ButtonName", FrameName, "UIPanelButtonTemplate")

Last edited by Yksrep : 07-26-13 at 11:06 PM.
  Reply With Quote
07-26-13, 12:43 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,307
It's certainly possible but a bit more context about what you want to achieve might help you get some more specific information.

Edit: The most basic (rough as guts) is you have a frame with 3 buttons. In the OnClick event for button A and B.

For A:
Code:
  self:GetParent().A_Clicked = true
  if self:GetParent().A_Clicked and self:GetParent().B_Clicked then
     --show button C
     self:GetParent().A_Clicked = nil
     self:GetParent().B_Clicked = nil
  end
For B:
Code:
  self:GetParent().B_Clicked = true
  if self:GetParent().A_Clicked and self:GetParent().B_Clicked then
     --show button C
     self:GetParent().A_Clicked = nil
     self:GetParent().B_Clicked = nil
  end
Very rudimentry and open to refinement depending on requirement.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 07-26-13 at 12:57 AM.
  Reply With Quote
07-26-13, 12:49 AM   #3
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,257
If by button presses you mean keyboard key presses, the answer is yes and no.

There is api to detect specific key presses (mainly the CTRL/ALT/SHIFT modifiers) as well you can detect keybound key combinations.

A generic key capturing solution is not trivial because making a frame that traps keyboard events generally means you lose control of the keyboard.

In any case this is a good starting point to explore possibilities: Frame:EnableKeyboard() Be sure to read the 'small print'

Last edited by Dridzt : 07-26-13 at 12:57 AM.
  Reply With Quote
07-26-13, 02:22 AM   #4
Yksrep
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 21
Originally Posted by Fizzlemizz View Post
It's certainly possible but a bit more context about what you want to achieve might help you get some more specific information.

Edit: The most basic (rough as guts) is you have a frame with 3 buttons. In the OnClick event for button A and B.

For A:
Code:
  self:GetParent().A_Clicked = true
  if self:GetParent().A_Clicked and self:GetParent().B_Clicked then
     --show button C
     self:GetParent().A_Clicked = nil
     self:GetParent().B_Clicked = nil
  end
For B:
Code:
  self:GetParent().B_Clicked = true
  if self:GetParent().A_Clicked and self:GetParent().B_Clicked then
     --show button C
     self:GetParent().A_Clicked = nil
     self:GetParent().B_Clicked = nil
  end
Very rudimentry and open to refinement depending on requirement.
Thanks,

A bit more for more context What I am trying to do is once someone selects the type of NPC they want to find (vendor trainer ect), and what City they are looking in (Stormwind, Thunder bluff ect) It will then either set a waypoint to that location Or if there are multiple allow the user to choose the NPC they want to visit.
  Reply With Quote
07-26-13, 10:59 PM   #5
Yksrep
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 21
If anyone stumbles upon this Post there is the working code.

Code:
--parent frame 
local frame = CreateFrame("Frame", "TestFrame", ParentUI) 
frame:SetSize(400, 200) 
frame:SetPoint("CENTER") 
local texture = frame:CreateTexture() 
texture:SetAllPoints() 
texture:SetTexture(0,0,0,0) 
frame.background = texture 


local button = CreateFrame("CheckButton", "ButtonA", TestFrame, "UIPanelButtonTemplate")
button:SetText("ButtonA")
button:SetPoint("LEFT",0,0)
button:SetWidth(120)
button:SetHeight(50)
button:SetScript("OnClick", 
  function()
    ButtonA:SetChecked()
  end);

local button = CreateFrame("CheckButton", "ButtonB", TestFrame, "UIPanelButtonTemplate")
button:SetText("ButtonB")
button:SetPoint("CENTER",0,0)
button:SetWidth(120)
button:SetHeight(50)
button:SetScript("OnClick", 
  function()
    ButtonB:SetChecked()
	if ButtonA:GetChecked() and ButtonB:GetChecked() then
	ButtonC:Show()
	end
  end);

local button = CreateFrame("CheckButton", "ButtonC", TestFrame, "UIPanelButtonTemplate")
button:SetText("ButtonC")
button:SetPoint("RIGHT",0,0)
button:SetWidth(120)
button:SetHeight(50)
button:Hide()
button:SetScript("OnClick", function()
				ButtonC:Hide()
				ButtonA:SetChecked(false)
				ButtonB:SetChecked(false)
				end)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Record button presses.

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