Make frames closable with the Escape key

From Wowpedia
Jump to: navigation, search

To make a frame close when the user presses the ESC (Escape) key, add its name to the UISpecialFrames table:

tinsert(UISpecialFrames, frame:GetName())

Note that in order for this to work, your frame must have a name.


The following XML snippet creates a frame that is closable by pressing Escape, and plays the sounds played when you open/close FrameXML panels (e.g. character frame).

<Frame name="ExampleFrame" parent="UIParent">
  <Size x="640" y="512" />
    <Anchor point="CENTER" />
      tinsert(UISpecialFrames, self:GetName());

EditBoxes and OnEscapePressed

EditBox widgets that have focus will handle the Escape key being pressed by firing their own OnEscapePressed widget handler, preventing your frame from being closed while an edit box has focus. You may set your own OnEscapePressed handler on your edit boxes to hide a frame if necessary:

editBox:SetScript("OnEscapePressed", function(self)