Home Reference Source
import Keasy from 'keasy/src/keasy.js'
public class | source

Keasy

Method Summary

Public Methods
public

after(amount: Number, unit: String): Keasy

Sets the amount of time and the unit of time this Keasy instance should wait until triggering the callback set in Keasy.then

public

is(keyString: String): Keasy

Binds a String representing a set of keys to this Keasy instance limiting when the callback Function passed to Keasy.then gets called.

public

off()

Removes the current listener from the EventTarget passed to Keasy.on.

public

on(eventTarget: EventTarget): Keasy

Binds an EventTarget to this Keasy instance.

public

then(callback: Function): Keasy

Binds a callback Function to this Keasy intsance.

public

when(eventType: String): Keasy

Sets the eventType String this Keasy instance will capture.

Public Methods

public after(amount: Number, unit: String): Keasy source

Sets the amount of time and the unit of time this Keasy instance should wait until triggering the callback set in Keasy.then

Params:

NameTypeAttributeDescription
amount Number

The amount of time Keasy waits until the EventTarget passed to Keasy.on stops firing KeyBoardEvents.

unit String
  • optional

This parameter is optional. If Keasy.after(amount,unit) is not passed a unit it defaults to milliseconds.

Return:

Keasy

Throw:

TypeError

Example:

Example 1
Keasy.when(Keasy.down).on(document.getElementById('fancyId')).then(function(){console.warn('Thank you!!')}).after(600);
Example 2
Keasy.when(Keasy.down).on(document.getElementById('fancyId')).then(function(){console.warn('Thank you!!')}).after(60000, Keasy.milliseconds);
Example 3
Keasy.when(Keasy.down).on(document.getElementById('fancyId')).then(function(){console.warn('Thank you!!')}).after(60, Keasy.seconds);
Example 4
Keasy.when(Keasy.down).on(document.getElementById('fancyId')).then(function(){console.warn('Thank you!!')}).after(1, Keasy.minutes);

public is(keyString: String): Keasy source

Binds a String representing a set of keys to this Keasy instance limiting when the callback Function passed to Keasy.then gets called. The keys in the {String} that is passed should be divided by a "+" character.

Params:

NameTypeAttributeDescription
keyString String

Return:

Keasy

Throw:

TypeError

If Keasy.is is not passed a {String} a TypeError is thrown.

Example:

Example 1
Keasy.when(Keasy.eventType).on(target).is(Keasy.ctrl+"+k").then(function(){console.warn("Event was CTRL+K")})

public off() source

Removes the current listener from the EventTarget passed to Keasy.on.

public on(eventTarget: EventTarget): Keasy source

Binds an EventTarget to this Keasy instance.

Params:

NameTypeAttributeDescription
eventTarget EventTarget

The targeted EventTarget Keasy should target for KeyBoardEvent.

Return:

Keasy

Throw:

TypeError

If Keasy.on is not passed a valid EventTarget it will throw a TypeError.

Example:

Example 1 (Using DOM)
Keasy.when(Keasy.down).on(document.getElementById('fancyId')).then(function(){console.warn("Keasy-peasy!")});
Example 2 (Using jQuery)
Keasy.when(Keasy.down).on($('#fancyId')[0]).then(function(){console.warn("Keasy-peasy!")});

public then(callback: Function): Keasy source

Binds a callback Function to this Keasy intsance. Not calling Keasy.then means Keasy produces no output. Keasy still catches events of the type passed to Keasy.when. Meaning you can call Keasy.then at another point in your code. See Example 3 for details.

Params:

NameTypeAttributeDescription
callback Function

The Function Keasy will call after it has caught a KeyBoardEvent.

Return:

Keasy

Throw:

TypeError

If Keasy.then(callback) is not passed a Function a TypeError is thrown.

Example:

Example 1
Keasy.when(Keasy.down).on(document.getElementById('fancyId')).then(function(){console.warn('Thank you!!')});
Example 2
Keasy.when(Keasy.down).on(document.getElementById('fancyId')).then(function(){document.getElementById('pretty').innterText = "Thank you!!"});
Example 3
var keasy = Keasy.when(Keasy.down).on(document.getElementById('fancyId'));
document.getElementById('pretty').innerText = "Waiting is so boring..";
function delayedThen(){
     document.getElementById('pretty').innerText = "Ok I'm fed up with waiting.. For the love of God please type something!";
     keasy.then(function(){
         document.getElementById('pretty').innerText = "Thank you!!";
     });
};
window.setTimeout(delayedThen, 5000);

public when(eventType: String): Keasy source

Sets the eventType String this Keasy instance will capture.

Params:

NameTypeAttributeDescription
eventType String
  • optional

This parameter is optional. If Keasy.when(eventType) is not passed an eventType it defaults to 'keydown'. Passing an eventType is advisable for readability purposes.

Return:

Keasy

Example:

Example 1 (Using Keasy shorthand)
Keasy.when(Keasy.down).on(document.getElementById('fancyId')).then(function(){console.warn("Keasy-peasy!")});
Example 2 (Using string)
Keasy.when('keydown').on(document.getElementById('fancyId')).then(function(){console.warn("Keasy-peasy!")});