@@ -49,7 +49,9 @@ These are nicely curated inputs from the keyboard. See the
4949lower-level interface that will let you define more complicated behavior.
5050!*/
5151
52−(function() {
52+function nativeKeyboard(elm) {
53+ 'use strict';
54+
5355 function keySignal(f) {
5456 var signal = Elm.Signal.lift(f)(Elm.Keyboard.Raw.keysDown);
5557 Elm.Keyboard.Raw.keysDown.defaultNumberOfKids += 1;
@@ -57,67 +59,36 @@ lower-level interface that will let you define more complicated behavior.
5759 return signal;
5860 }
5961
60− function dir(left,right,up,down) {
62+ function dir(up) { return function(down) {
63+ return function(left) { return function(right) {
6164 function f(ks) {
6265 var x = 0, y = 0;
63− while (ks[0] == "Cons") {
64− switch (ks[1]) {
66+ while (ks.ctor == "Cons") {
67+ switch (ks._0) {
6568 case left : --x; break;
6669 case right: ++x; break;
6770 case up : ++y; break;
6871 case down : --y; break;
6972 }
70− ks = ks[2];
73+ ks = ks._1;
7174 }
72− return { _:[true], x:[x], y:[y] };
75+ return { _:{}, x:x, y:y };
7376 }
7477 return keySignal(f);
78+ }}}
7579 }
7680
7781 function is(key) {
7882 function f(ks) {
79− while (ks[0] == "Cons") {
80− if (key == ks[1]) return true;
81− ks = ks[2];
83+ while (ks.ctor == "Cons") {
84+ if (key == ks._0) return true;
85+ ks = ks._1;
8286 }
8387 return false;
8488 }
8589 return keySignal(f);
8690 }
8791
88− /*[Directions]*/
89−
90− /** arrows : Signal { x:Int, y:Int }
91− A signal of records indicating which arrow keys are pressed.
92−
93− `{ x = 0, y = 0 }` when pressing no arrows.
94− `{ x =-1, y = 0 }` when pressing the left arrow.
95− `{ x = 1, y = 1 }` when pressing the up and right arrows.
96− `{ x = 0, y =-1 }` when pressing the down, left, and right arrows.
97− **/
98− Elm.Keyboard.arrows = dir(37,39,38,40);
99−
100− /** wasd : Signal { x:Int, y:Int }
101− Just like the arrows signal, but this uses keys w, a, s, and d,
102− which are common controls for many computer games.
103− **/
104− Elm.Keyboard.wasd = dir(65,68,87,83);
105−
106− /*[Modifiers]*/
107−
108− /** shift : Signal Bool
109− Whether the shift key is pressed.
110− **/
111− Elm.Keyboard.shift = is(16);
112−
113− /** ctrl : Signal Bool
114− Whether the control key is pressed.
115− **/
116− Elm.Keyboard.ctrl = is(17);
117−
118− /** space : Signal Bool
119− Whether the space key is pressed.
120− **/
121− Elm.Keyboard.space = is(32);
92+ elm.Native.Keyboard = { isDown:is, dir:dir };
12293
123−}());
94+}