Thanks to visit codestin.com
Credit goes to lib.haxe.org

keyboard

An alternative way to define keyboard listeners
https://github.com/peteshand/keyboard

To install, run:

haxelib install keyboard 1.1.0 

See using Haxelib in Haxelib documentation for more information.

README.md

Overview

This library offers an alternative way to define keyboard listeners. Currently the library only supports openfl based appplications. Rather than listening to a keyboard event and then filtering for switch key is pressed in the callback function, this is defined when the listener is added.

The following example adds a keyboard listener for when the "Enter" is pressed.

import keyboard.Key;
import keyboard.Keyboard;

...

Keyboard.onPress(Key.ENTER, () -> {
   trace('press');
} );

There is also an onRelease function.

Keyboard.onRelease(Key.ENTER, () -> {
   trace('release');
} );

If you want to add ctrl, alt, shirt modifiers these can be daisy chained after the onPress or onRelease functions. The following example will be triggered when the A key is pressed while both Shift and Ctrl are held down and Alt is not.

Keyboard.onPress(Key.A, () -> {
   trace('press');
} ).shift(true).ctrl(true).alt(false);

If a modifier is not set then the callback will be triggered regardless of it the modifier is being pressed or not. So in the below case the callback will be triggered when the A key is pressed while both Shift and Ctrl are held down and Alt is pressed or not pressed.

Keyboard.onPress(Key.A, () -> {
   trace('press');
} ).shift(true).ctrl(true);

Arguments can be passed as follows:

Keyboard.onPress(Key.A, example, [5, "test"] );

function example(value1:Int, value2:String)
{

}

Removing listners can be accomplished as follows:

Keyboard.removePress( example );
//or
Keyboard.removeRelease( example );

function example(value1:Int, value2:String)
{

}

If not Key is defined then the callback will be triggered regardless of which key is pressed.

Keyboard.onPress(() -> {
   trace('press');
} ).
Contributors
p.j.shand
Version
1.1.0
Published
5 years ago
Dependencies
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub