$(document).ready(function() {
    var EVENTS_ENDPOINT = '/events';
    var MAIN_MEDIA_ID = '#main-media';


    var nameOfMouseButton = Object.create(null);
    nameOfMouseButton[1] = 'left';
    nameOfMouseButton[2] = 'middle';
    nameOfMouseButton[3] = 'right';

    var mouseEventHandler = function(event) {
        notifyEvent({
            type: event.type,
            content: {
                button: nameOfMouseButton[event.which],
                coordinates: {
                    x: event.pageX,
                    y: event.pageY
                }
            }
        });
    };

    var notifyEvent = function(eventData) {
        $.post(EVENTS_ENDPOINT, eventData, function(responseData, statusCode) {
            if (statusCode !== '200') return;

            var newMediaUrl = responseData.media.content;
            $(MAIN_MEDIA_ID).attr('src', newMediaUrl);
        }, 'json');
    };


    $(MAIN_MEDIA_ID).mousedown(mouseEventHandler);
    $(MAIN_MEDIA_ID).mouseup(mouseEventHandler);
});

@@ -101,17 +101,16 @@
 edia';%0A%0A
-%0A
     var 
@@ -255,24 +255,25 @@
 = 'right';%0A%0A
+%0A
     var mous
@@ -269,29 +269,24 @@
    var mouse
-Event
 Handler = fu
@@ -325,67 +325,658 @@
 ent(
-%7B%0A            type: event.type,%0A            content: %7B%0A    
+pickMouseEventData(event));%0A    %7D;%0A%0A    var notifyEvent = function(eventData) %7B%0A        $.ajax(%7B%0A            type: 'POST',%0A            url: EVENTS_ENDPOINT,%0A            data: JSON.stringify(eventData),%0A            contentType: 'application/json',%0A            success: function(responseData, statusCode) %7B%0A                if (statusCode !== '200') return;%0A%0A                var newMediaUrl = responseData.media.content;%0A                $(MAIN_MEDIA_ID).attr('src', newMediaUrl);%0A            %7D%0A        %7D);%0A    %7D;%0A%0A    var pickMouseEventData = function(event) %7B%0A        var mouseEventData = pickCommonEventData(event);%0A        mouseEventData.content = %7B%0A
     
@@ -1035,20 +1035,16 @@
         
-    
 coordina
@@ -1066,20 +1066,16 @@
         
-  
-  
 x: event
@@ -1082,20 +1082,16 @@
 .pageX,%0A
-    
         
@@ -1113,32 +1113,38 @@
 t.pageY%0A        
+    %7D%0A
         %7D%0A      
@@ -1128,32 +1128,34 @@
      %7D%0A        %7D
+;%0A
 %0A            %7D%0A 
@@ -1139,37 +1139,196 @@
     %7D;%0A%0A        
-    %7D
+return mouseEventData;%0A    %7D;%0A%0A    var pickCommonEventData = function(event) %7B%0A        return %7B%0A            type: event.type,%0A            timestamp: event.timeStamp
 %0A        %7D);%0A   
@@ -1313,33 +1313,32 @@
 eStamp%0A        %7D
-)
 ;%0A    %7D;%0A%0A    va
@@ -1327,32 +1327,34 @@
  %7D;%0A    %7D;%0A%0A
+%0A%0A
     var 
 notifyEvent 
@@ -1337,35 +1337,38 @@
 %0A%0A%0A%0A    var 
-notifyEvent
+keydownHandler
  = function(
@@ -1364,36 +1364,32 @@
 = function(event
-Data
 ) %7B%0A        $.po
@@ -1388,42 +1388,126 @@
     
-$.post(EVENTS_ENDPOINT, event
+if (isJustAModifierKey(event)) return;%0A%0A        notifyEvent(pickKeydownData(event));%0A    %7D;%0A%0A    var pickKeydown
 Data
-,
+ =
  fun
@@ -1516,214 +1516,736 @@
 ion(
-responseData, statusCode) %7B%0A            if (statusCode !== '200') return;%0A%0A            var newMediaUrl = responseData.media.content;%0A            $(MAIN_MEDIA_ID).attr('src', newMediaUrl);%0A        %7D, 'json')
+event) %7B%0A        var keydownData = pickCommonEventData(event);%0A        keydownData.content = %7B%0A            code: event.which,%0A            modifiers: %5B'ctrlKey', 'altKey', 'shiftKey', 'metaKey'%5D.filter(function(modifierKeyName) %7B%0A                return event%5BmodifierKeyName%5D;%0A            %7D)%0A        %7D;%0A%0A        return keydownData;%0A    %7D;%0A%0A    var isJustAModifierKey = function(event) %7B%0A        // see http://unixpapa.com/js/key.html%0A        return %5B%0A            16, // Shift%0A            17, // Ctrl %7C%7C Left and Right Command (Opera)%0A            18, // Alt%0A            91, // Left Command (Safari)%0A            224, // Left and Right Command (Firefox)%0A            93 // Right Command (Safari)%0A        %5D.indexOf(event.which) !== -1
 ;%0A  
@@ -2247,24 +2247,26 @@
 1;%0A    %7D;%0A%0A%0A
+%0A%0A
     $(MAIN_M
@@ -2285,29 +2285,24 @@
 sedown(mouse
-Event
 Handler);%0A  
@@ -2333,21 +2333,54 @@
 up(mouse
-Event
+Handler);%0A%0A    $(this).keydown(keydown
 Handler)

Implement keydown handler.