Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Hotkey library for AS3
ActionScript
branch: master
Failed to load latest commit information.
bin Added license
build Added build script
lib
src/com/destroytoday/hotkey Added license
test Added build script
.gitignore Added build script
LICENSE Added license
README.textile
build.xml Added build script

README.textile

Hotkey

Overview

This is a library that eases the pain of hotkey management in AS3 apps.

Hotkeys

Creating and adding

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");

Listening

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);

Case-sensitivity

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);

Explicit modifiers

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);

Special characters

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("©");

Numbers

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);
Something went wrong with that request. Please try again.