obiot/melonJS — pull request #97 by parasyte (2012-08-25 06:46:55+00:00)
Title: Publish on keydown and keyup events

For background, this feature will help with asynchronously handling key events. Especially in the case where the user wants to resume a paused game with a key: https://groups.google.com/forum/?fromgroups=#!topic/melonjs/7LnZpwdtWFM

The "current" solution available is creating an interval that will periodically poll the key to determine when it's time to resume gameplay. This patch allows us to be kind to battery life:

```JavaScript
if (me.input.isKeyPressed("pause")) {
me.state.pause();

var resume_event = me.event.subscribe(me.event.KEYDOWN, function check_resume(action) {
if (me.input.isKeyPressed("pause")) {
me.event.unsubscribe(resume_event);
me.state.resume();
}
});
}
```

General use patterns for these callbacks is:
* Use `me.input.isKeyPressed(...)` inside the callback if the key was binded with the `lock` parameter set to `true`.
* Else use `if (action == ...)`

Maybe this should be documented somehow?