Show/hide Frame on button/keybind?
So I want to make a frame that shows/hides on a toggle function when a button is clicked or a specific keybind is pressed. How would I go about doing this?
|
Not directly related but maybe it can help you out aswell:
http://wowpedia.org/API_IsModifierKeyDown You could register the MODIFIER_STATE_CHANGED event and check if a modifier key is clicked. |
I did a bit of fiddling, unfortunately I'm away from the desktop so I can't test it but I think I can do something like this for the key press, I'm probably way off though.
Code:
frame:SetScript("OnMouseDown", function(self, btn) |
Haha, that's probably the highest concentration of Lua syntax errors I've ever seen in so little code. :p
Anyway, I'm not exactly sure what you're trying to do, but even if you fix the syntax errors on your code, I don't think it's going to do it. For one, your code basically says "show the frame on shift-right click, hide it on any other type of click". For another, you're using that script on the frame itself, and you can't click on a frame that's hidden, so you'd never be able to re-show it. Do you want to show the frame when the button/key is pressed, and hide it again when the button/key is released; or show the frame on the first click/press and hide it on the second click/press? |
I wanna show it when pressed hide when released.
|
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 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") |
I should be able to just use UIParent for the frame shouldn't I?
|
For which frame?
You should absolutely not use SetScript on the UIParent, if that's what you mean, and you really shouldn't be registering new events on it either. Just create your own frame. Takes 1 line of code and avoids all the potential problems. |
All times are GMT -6. The time now is 04:15 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI