   key_S = 83
   key_X = 88
   key_Z = 90
+
+  button_keys = [key_tab, key_space, key_home, key_left_arrow, key_right_arrow, key_down_arrow]
+  rotate_keys = [key_C, key_Z, key_A, key_D, key_S, key_X]
+  turn_keys   = [key_J, key_K, key_L]
+
+  turn_for = {}
+  turn_for[key_J] = "U"
+  turn_for[key_K] = "F"
+  turn_for[key_L] = "R"

    @dom_handler.has_focus(true)

  @key_down: (e) ->
    if e.shiftKey
      turns = 3
    else
      turns = if e.ctrlKey then 2 else 1

    switch e.keyCode
      when key_tab
        new_focus = if e.shiftKey then @active_display.previous_display() else @active_display.next_display()
        this.set_active_display(new_focus)
      when key_home, key_down_arrow then this._fake_click_down(@dom_handler.reset)
      when key_left_arrow  then b = (if e.shiftKey then @dom_handler.reset else @dom_handler.prev); this._fake_click_down(b)
      when key_right_arrow then b = (if e.shiftKey then @dom_handler.active_play_or_pause else @dom_handler.next); this._fake_click_down(b)
      when key_space       then this._fake_click_down(@dom_handler.active_play_or_pause)
      when key_C then this._rotate('up', 1)
      when key_Z then this._rotate('up',-1)
      when key_A then this._rotate('dr', 1)
      when key_D then this._rotate('dr',-1)
      when key_S then this._rotate('dl', 1)
      when key_X then this._rotate('dl',-1)
      when key_J then this._move("U#{turns}")
      when key_K then this._move("F#{turns}")
      when key_L then this._move("R#{turns}")
      else
        handled = false

    !handled

  @key_up: (e) ->
    switch e.keyCode
      when key_home, key_left_arrow, key_right_arrow, key_space
        if @down_button
          this._fake_click_up(@down_button)
          @down_button = null
      else
        handled = false

    !handled

  @_fake_click_down: (button) ->
    unless button.attr("disabled")

#= require roofpig/utils

#This is all global data and functions. Think of it as a "singleton" class.
class @InputHandler


  @set_active_display: (new_active) ->
    @dom_handler.has_focus(false) if @active_display
