<commit_before># Define keyboard input service
registerService "Keyboard", (options) ->
  options = _.defaults options,
    elementSelector: "#gameCanvas"

  keysDown = {}

  # Use the KeyboardService event namespace
  $(options.elementSelector).on "keydown.GE.KeyboardService keyup.GE.KeyboardService", (event) ->
    # jQuery standardizes the keycode into http://api.jquery.com/event.which/
    if event.type == "keydown"
      keysDown[event.which] = true
    else
      delete keysDown[event.which]

  return {
    provideData: -> return { "keysDown": keysDown }

    establishData: -> # NOOP. Input service does not take data

    # Remove all events
    destroy: -> $(options.elementSelector).off(".GE.KeyboardService")
  }

# Define mouse input service
registerService "Mouse", (options) ->
  options = _.defaults options,
    elementSelector: "#gameCanvas"

  mouse =
    down: false
    position: null

  # Use the KeyboardService event namespace
  $(options.elementSelector).on "mousedown.GE.MouseService mouseup.GE.MouseService mouseup.GE.MouseService mousemove.GE.MouseService mouseleave.GE.MouseService", (event) ->
    # jQuery standardizes the keycode into http://api.jquery.com/event.which/
    switch event.type 
      when "mousedown" then mouse.down = true
      when "mouseup" then mouse.down = false
      when "mouseleave" 
        mouse.down = false
        mouse.position = null
      when "mousemove"
        # Get position relative to canvas.
        # Based on http://www.html5canvastutorials.com/advanced/html5-canvas-mouse-coordinates/
        rect = $(options.elementSelector)[0].getBoundingClientRect()
        mouse.position = 
          x: event.clientX - rect.left
          y: event.clientY - rect.top

  return {
    provideData: -> return mouse

    establishData: -> # NOOP. Input service does not take data

    # Remove all events
    destroy: -> $(options.elementSelector).off(".GE.MouseService")
  }


<commit_msg>fixed keyboard tracking events after losing focus<commit_after># Define keyboard input service
registerService "Keyboard", (options) ->
  options = _.defaults options,
    elementSelector: "#gameCanvas"

  keysDown = {}

  # Use the KeyboardService event namespace
  $(options.elementSelector).on "keydown.GE.KeyboardService keyup.GE.KeyboardService blur.GE.KeyboardService", (event) ->
    # jQuery standardizes the keycode into http://api.jquery.com/event.which/
    switch event.type 
      when "keydown" then keysDown[event.which] = true
      when "keyup" then delete keysDown[event.which]
      when "blur" then keysDown = {}
      else throw new Error("Unexpected event type")      

  return {
    provideData: -> return { "keysDown": keysDown }

    establishData: -> # NOOP. Input service does not take data

    # Remove all events
    destroy: -> $(options.elementSelector).off(".GE.KeyboardService")
  }

# Define mouse input service
registerService "Mouse", (options) ->
  options = _.defaults options,
    elementSelector: "#gameCanvas"

  mouse =
    down: false
    position: null

  # Use the KeyboardService event namespace
  $(options.elementSelector).on "mousedown.GE.MouseService mouseup.GE.MouseService mouseup.GE.MouseService mousemove.GE.MouseService mouseleave.GE.MouseService", (event) ->
    # jQuery standardizes the keycode into http://api.jquery.com/event.which/
    switch event.type 
      when "mousedown" then mouse.down = true
      when "mouseup" then mouse.down = false
      when "mouseleave" 
        mouse.down = false
        mouse.position = null
      when "mousemove"
        # Get position relative to canvas.
        # Based on http://www.html5canvastutorials.com/advanced/html5-canvas-mouse-coordinates/
        rect = $(options.elementSelector)[0].getBoundingClientRect()
        mouse.position = 
          x: event.clientX - rect.left
          y: event.clientY - rect.top
      else throw new Error("Unexpected event type")

  return {
    provideData: -> return mouse

    establishData: -> # NOOP. Input service does not take data

    # Remove all events
    destroy: -> $(options.elementSelector).off(".GE.MouseService")
  }



{'fraction_non_alphanumeric': 0.10748792270531402, 'fraction_numerical': 0.0014492753623188406, 'mean_word_length': 3.091897233201581, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3489236', 'n_tokens_mistral': 1171, 'n_tokens_neox': 1138, 'n_words': 315}