 $(document).bind 'keydown', 'up', (ev) -> moveCellCursorUp()
 $(document).bind 'keydown', 'right', (ev) -> moveCellCursorRight()
 $(document).bind 'keydown', 'left', (ev) -> moveCellCursorLeft()
+
+$(document).keypress (ev) ->
+  if ev.target.nodeName.toLowerCase() == "body"
+    # we're not inside a textarea, create a new input cell
+    inputCellDiv = $ '<div class="cell input"><textarea id="input_1" rows="3" cols="80"></textarea></div>'
+    $(findOrCreateCellCursor()).replaceWith(inputCellDiv)
+    textarea = inputCellDiv.children("textarea")[0]
+    textarea.value = String.fromCharCode(ev.which)
+    editor = makeInputCell(textarea)
+    setCursorToEndOfDoc(editor)
+    editor.focus()

    console.error error
    newOutputCell.html displayPretty(error) + "<br>See console for details."
    newOutputCell.addClass "error"

findOrCreateCellCursor = () ->
  cursor = $("#cursor")



moveCellCursorDown = () ->
  cursor = findOrCreateCellCursor()
  cell = $(cursor).next("div.cell")
  if cell
    insertCellCursorAfter(cell)

moveCellCursorUp = () ->
  cursor = findOrCreateCellCursor()
  cell = $(cursor).prev("div.cell")
  if cell
    insertCellCursorBefore(cell)

moveCellCursorRight = () ->
  cursor = findOrCreateCellCursor()
  nextCell = $(cursor).next(".cell")
  textarea = nextCell.children("textarea")
