@@ -105,6 +105,41 @@ var Signal = function() {
105105 height: Elm.Lift(function(p){return p[2];},[dimensions]) };
106106 }();
107107
108+ var Keyboard = { Raw : function() {
109+ var keysDown = Elm.Input(["Nil"]);
110+ var charPressed = Elm.Input(["Nothing"]);
111+ function remove(x,xs) {
112+ if (xs[0] === "Nil") return xs;
113+ if (xs[1] === x) return xs[2];
114+ return ["Cons", xs[1], remove(x,xs[2])];
115+ }
116+ function has(x,xs) {
117+ while (xs[0] !== "Nil") {
118+ if (xs[1] === x) return true;
119+ xs = xs[2];
120+ }
121+ return false;
122+ }
123+ addListener(document, 'keydown', function(e) {
124+ if (has(e.keyCode, keysDown.value)) return;
125+ Dispatcher.notify(keysDown.id, ["Cons", e.keyCode, keysDown.value]);
126+ });
127+ addListener(document, 'keyup', function(e) {
128+ var codes = remove(e.keyCode, keysDown.value)
129+ Dispatcher.notify(keysDown.id, codes);
130+ });
131+ addListener(window, 'blur', function(e) {
132+ Dispatcher.notify(keysDown.id, ["Nil"]);
133+ });
134+ addListener(document, 'keypress', function(e) {
135+ Dispatcher.notify(charPressed.id, ["Just",e.charCode || e.keyCode]);
136+ Dispatcher.notify(charPressed.id, ["Nothing"]);
137+ });
138+ return {keysDown:keysDown,
139+ charPressed:charPressed};
140+ }()
141+ };
142+
108143 var HTTP = function() {
109144 var fetch = function(how) { return function(url) {
110145 var thread = Elm.Input(["Waiting"]);
@@ -119,7 +154,7 @@ var Signal = function() {
119154 : ["Failure", request.status, toElmString(request.statusText)]);
120155 }
121156 };
122− request.open(how, String.toText(url), true);
157+ request.open(how, Data.String.toText(url), true);
123158 request.send(null);
124159 return thread;
125160 };
@@ -147,7 +182,7 @@ var Signal = function() {
147182 : ["Failure", request.status, toElmString(request.statusText)]]);
148183 }
149184 };
150− request.open(how, String.toText(strOpt[1]), true);
185+ request.open(how, Data.String.toText(strOpt[1]), true);
151186 request.send(null);
152187 return [];
153188 }
@@ -249,6 +284,11 @@ var Signal = function() {
249284 button:button};
250285 }();
251286
252− return {Mouse:Mouse, Time:Time, Window:Window,
253− HTTP:HTTP, Random:Random, Input:Input };
287+ return {Mouse:Mouse,
288+ Keyboard:Keyboard,
289+ Time:Time,
290+ Window:Window,
291+ HTTP:HTTP,
292+ Random:Random,
293+ Input:Input };
254294}();