Created
February 14, 2012 21:32
-
-
Save jgranick/1830627 to your computer and use it in GitHub Desktop.
How to bind keyboard events using the "KeyBinding" library (NME recipe)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.eclecticdesignstudio.control.KeyBinding; | |
import nme.display.Sprite; | |
import nme.text.TextField; | |
/** | |
* @author Joshua Granick | |
*/ | |
class KeyboardTest extends Sprite { | |
private var label:TextField; | |
public function new () { | |
super (); | |
KeyBinding.addOnPress ("a", Keyboard_onPressA); | |
KeyBinding.addOnRelease ("a", Keyboard_onReleaseA); | |
} | |
// Event Handlers | |
private function Keyboard_onPressA ():Void { | |
// user pressed the A key | |
} | |
private function Keyboard_onReleaseA ():Void { | |
// user released the A key | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Although you can listen to keyboard events directly, the KeyBinding library makes it easier to bind or unbind actions to keys on the keyboard.
You can install it with "haxelib install keybinding" from a command-prompt or terminal, then you can include it in your project with <haxelib name="keybinding" /> in your NMML project file.