Permalink
Browse files

Optimizes key handlers for sample_game.

  • Loading branch information...
1 parent 3265da1 commit 840133effb82b4a80064d1631a5f7310339b7cb9 @jeremyckahn committed Aug 24, 2012
Showing with 9 additions and 2 deletions.
  1. +9 −2 ui/sample_game/js/src/key-input-demo.js
@@ -48,21 +48,28 @@
var dtArr = Array.prototype.slice.call(dts, 0);
dtArr.forEach(function (dt) {
+ var isPressed = false;
var dd = dt.nextElementSibling;
dd.textContent = 'Not pressed';
var dtKeycode = +dt.dataset.keycode;
var keydownHandlerObject = {};
keydownHandlerObject.keycode = dtKeycode;
keydownHandlerObject.fn = function () {
- dd.textContent = 'Pressed';
+ if (!isPressed) {
+ dd.textContent = 'Pressed';
+ }
+ isPressed = true;
};
keyHandlers.keydown.push(keydownHandlerObject)
var keyupHandlerObject = {};
keyupHandlerObject.keycode = dtKeycode;
keyupHandlerObject.fn = function () {
- dd.textContent = 'Not pressed';
+ if (isPressed) {
+ dd.textContent = 'Not pressed';
+ }
+ isPressed = false;
};
keyHandlers.keyup.push(keyupHandlerObject)
});

0 comments on commit 840133e

Please sign in to comment.