This is a library that eases the pain of hotkey management in AS3 apps.
To create and add a hotkey to the manager, you can manually instantiate the hotkey and use the addHotkey method.
var hotkeyManager:HotkeyManager = new HotkeyManager(); hotkeyManager.addStage(stage); var openHotkey:Hotkey = new Hotkey("command+o"); hotkeyManager.addHotkey(openHotkey);
Or, you can use the addHotkeyCombo method to instantiate and automatically add a hotkey to the manager in one line.
var openHotkey:Hotkey = hotkeyManager.addHotkeyCombo("command+o");
Hotkeys use signals to indicate they have been executed, so you can listen directly to the signal or map it to a command.
hotkeyManager.addHotkeyCombo("command+c").executed.add(copyHotkeyHandler);
signalCommandMap.mapSignal(hotkeyManager.addHotkeyCombo("command+c").executed, CopyCommand);
Char-based hotkeys are case-sensitive, as demonstrated with the conditions below:
new Hotkey("command+f") != new Hotkey("command+F"); new Hotkey("command+F") == new Hotkey("command+shift+" + Keyboard.F);
Though you can use ‘F’ to indicate ‘shift+f’, you can make your hotkeys easier to understand with explicit modifiers and key codes.
new Hotkey("command+" + Keyboard.F); new Hotkey("command+shift+" + Keyboard.F);
Char-based hotkeys can only use command and control modifiers, so using shift and alt will throw an error.
new Hotkey("shift+g"); new Hotkey("alt+g");
Instead, use key codes.
new Hotkey("shift+" + Keyboard.G); new Hotkey("alt+" + Keyboard.G);
Or, if the intended hotkey is ‘©’, use that char, since its hotkey on a western keyboard (alt+g) might be different on other keyboards.
new Hotkey("©");
Don’t use char-based hotkeys for numbers because numbers will be parsed as key codes.
new Hotkey("command+8") == new Hotkey("command+" + Keyboard.BACKSPACE);
Instead, use key codes.
new Hotkey("command+" + Keyboard.NUMBER_8);