View Single Post
11-10-13, 12:08 AM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If you want to use mouse buttons, that's fairly easy, though you'll have to think about what you want to click on to show the frame, since you can't click on it while hidden. You could either use a second frame as a small always-visible area for clicking (eg. a tab or button) or hook the OnMouseDown script for the WorldFrame and show your frame if the cursor was in a particular area.

Code:
WorldFrame:HookScript("OnMouseDown", function(self, button)
   if button == "RightButton" and MyFrame:IsMouseOver() then
      MyFrame:Show()
   end
end)
WorldFrame:HookScript("OnMouseUp", function(self, button)
   MyFrame:Hide()
end)
^ Note that I'm not actually sure that will work, since I don't know that :IsMouseOver() will works for hidden frames. If it doesn't, you'd need to manually determine the boundaries of your frame and check the coordinates of the cursor to make sure it was within those boundaries.

If you want to use keyboard keys, that's only really possible if you want to use Alt, Ctrl, Shift, or some combination thereof. The only way to detect other keys is to keyboard-enable your frame, which basically makes it behave like a focused editbox, intercepting all keyboard input and preventing the use of keybinds for anything else.

Code:
MyFrame:RegisterEvent("MODIFIER_STATE_CHANGED")
MyFrame:SetScript("OnEvent", function(self, event, key, pressed)
   if key == "LALT" or key == "RALT" then
      if pressed == 1 then
         self:Show()
      else
         self:Hide()
      end
   end
end)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote