12.07.2015 Views

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

322 Part III ■ Advanced Addon Techniquesmodifier == “CTRL“ ormodifier == “ALT“ orkey == “UNKNOWN“ thenreturnendWhen OnKeyDown receives a modifier key, it differentiates between keys onthe left <strong>and</strong> right sides <strong>of</strong> the keyboard. For example, the left shift key is calledLSHIFT <strong>and</strong> the right shift key is called RSHIFT. The first line in the precedingsnippet eliminates a bit <strong>of</strong> redundancy in the if clause by stripping the firstcharacter <strong>of</strong>f the key. You also check <strong>for</strong> UNKNOWN, which is triggered by keysthat <strong>WoW</strong> doesn’t recognize (like Scroll Lock <strong>and</strong> Pause on Windows).You should also add special treatment <strong>for</strong> the key normally used to takescreenshots. Otherwise there would be no way to take a screenshot <strong>of</strong> thebinding. Add the following code immediately after the previous snippet:if GetBindingFromClick(key) == “SCREENSHOT“ thenTakeScreenshot()returnendThe function GetBindingFromClick, defined in FrameXML\UIParent.lua,returns the action associated with the current key press, if any. If the actionturns out to be SCREENSHOT, this code takes a screenshot <strong>and</strong> aborts the function.Once you’ve eliminated the special cases, you can begin building thekey argument. Although you ignored the modifier keys when they directlytriggered OnKeyDown, you need to check their status to apply the appropriateprefixes to the key. Add this code following the screenshot check:if IsShiftKeyDown() thenkey = “SHIFT-“..keyendif IsControlKeyDown() thenkey = “CTRL-“..keyendif IsAltKeyDown() thenkey = “ALT-“..keyendNote that the order <strong>of</strong> these modifier checks is crucial; SetBinding onlyaccepts modifier prefixes in the order ALT-CTRL-SHIFT-. In this snippet,you’re adding them one at a time, as applicable, to the beginning <strong>of</strong> thekey. If you pressed A with all the modifier keys held down, the key parameterwould progress as follows:ASHIFT-A

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!