Permalink
Browse files

browser control file

  • Loading branch information...
1 parent 441476b commit daf48c06ddc4bbf18257a4be4348ed0cf3a3d216 @substack committed Oct 5, 2012
Showing with 49 additions and 0 deletions.
  1. +49 −0 browser/control.js
View
@@ -0,0 +1,49 @@
+module.exports = function (client) {
+ var ctrl = {
+ f: client.front,
+ t: client.counterClockwise,
+ a: client.up,
+ s: client.left,
+ }
+
+ var cmd = {
+ left: function (n) { ctrl.t(n) },
+ right: function (n) { ctrl.t(-1 * n) },
+
+ shift_left: function (n) { ctrl.t(.5 * n) },
+ shift_right: function (n) { ctrl.t(-0.5 * n) },
+
+ up: function (n) { ctrl.f(1 * n) },
+ down: function (n) { ctrl.f(-1 * n) },
+
+ ',': function (n) { ctrl.s(-1 * n) },
+ '.': function (n) { ctrl.s(1 * n) },
+
+ shift_up: function (n) { ctrl.a(1 * n) },
+ shift_down: function (n) { ctrl.a(-1 * n) },
+
+ shift_t: function (n) {
+ client.takeoff(1 * n)
+ client.disableEmergency()
+ },
+ shift_l: function (n) { client.land(1 * n) },
+
+ }
+
+ window.addEventListener('keydown', function (ev) {
+ var c = commandOf(ev)
+ if (c) c(1)
+ })
+
+ window.addEventListener('keyup', function (ev) {
+ var c = commandOf(ev)
+ if (c) c(0)
+ })
+
+ function commandOf (ev) {
+ var name = ev.keyIdentifier.toLowerCase()
+ var meta = ev.shiftKey ? 'shift_' : ''
+ return cmd[meta + name]
+ || cmd[meta + String.fromCharCode(ev.keyCode).toLowerCase()]
+ }
+}

0 comments on commit daf48c0

Please sign in to comment.