Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Optimizes key handlers for sample_game.

  • Loading branch information...
commit 840133effb82b4a80064d1631a5f7310339b7cb9 1 parent 3265da1
Jeremy Kahn authored

Showing 1 changed file with 9 additions and 2 deletions. Show diff stats Hide diff stats

  1. +9 2 ui/sample_game/js/src/key-input-demo.js
11 ui/sample_game/js/src/key-input-demo.js
@@ -48,6 +48,7 @@
48 48 var dtArr = Array.prototype.slice.call(dts, 0);
49 49
50 50 dtArr.forEach(function (dt) {
  51 + var isPressed = false;
51 52 var dd = dt.nextElementSibling;
52 53 dd.textContent = 'Not pressed';
53 54 var dtKeycode = +dt.dataset.keycode;
@@ -55,14 +56,20 @@
55 56 var keydownHandlerObject = {};
56 57 keydownHandlerObject.keycode = dtKeycode;
57 58 keydownHandlerObject.fn = function () {
58   - dd.textContent = 'Pressed';
  59 + if (!isPressed) {
  60 + dd.textContent = 'Pressed';
  61 + }
  62 + isPressed = true;
59 63 };
60 64 keyHandlers.keydown.push(keydownHandlerObject)
61 65
62 66 var keyupHandlerObject = {};
63 67 keyupHandlerObject.keycode = dtKeycode;
64 68 keyupHandlerObject.fn = function () {
65   - dd.textContent = 'Not pressed';
  69 + if (isPressed) {
  70 + dd.textContent = 'Not pressed';
  71 + }
  72 + isPressed = false;
66 73 };
67 74 keyHandlers.keyup.push(keyupHandlerObject)
68 75 });

0 comments on commit 840133e

Please sign in to comment.
Something went wrong with that request. Please try again.