summaryrefslogtreecommitdiff
path: root/maize-maze/js/keyboard.js
blob: 2196834f7fec03d19394bf05b90ce5a16d0e86f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Shameless stolen code from "Process the Input" presentation
let input = (function() {
  function Keyboard() {
    let that = {
      keys : {}
    };
    function keyPress(e) {
      that.keys[e.key] = e.timeStamp;
    }
    function keyRelease(e) {
      delete that.keys[e.key];
    }
    window.addEventListener('keydown', keyPress);
    window.addEventListener('keyup', keyRelease);
    
    return that;
  }
  
  return {
    Keyboard : Keyboard
  };
}());