Make frames closable with the Escape key
To make a frame close when the user presses the ESC (Escape) key, add its name to the
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" /> <Anchors> <Anchor point="CENTER" /> </Anchors> <Scripts> <OnLoad> tinsert(UISpecialFrames, self:GetName()); </OnLoad> <OnShow> PlaySound("igCharacterInfoOpen"); </OnShow> <OnHide> PlaySound("igCharacterInfoClose"); </OnHide> </Scripts> </Frame>
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) self:GetParent():Hide() end)