Index: client/Client/Client.vcxproj
===================================================================
--- client/Client/Client.vcxproj	(revision 9a3e6b166fac0f317e650d6c558d94c60ef9600e)
+++ client/Client/Client.vcxproj	(revision 6475138037f8825ef1e75833efa2789c0ebcabdd)
@@ -65,4 +65,5 @@
   <ItemGroup>
     <ClCompile Include="..\..\common\message.cpp" />
+    <ClCompile Include="chat.cpp" />
     <ClCompile Include="main.cpp" />
   </ItemGroup>
@@ -70,4 +71,5 @@
     <ClInclude Include="..\..\common\compiler.h" />
     <ClInclude Include="..\..\common\message.h" />
+    <ClInclude Include="chat.h" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Index: client/Client/Client.vcxproj.filters
===================================================================
--- client/Client/Client.vcxproj.filters	(revision 9a3e6b166fac0f317e650d6c558d94c60ef9600e)
+++ client/Client/Client.vcxproj.filters	(revision 6475138037f8825ef1e75833efa2789c0ebcabdd)
@@ -17,4 +17,7 @@
       <UniqueIdentifier>{9ecfb491-9e8e-4a29-bc07-dd887204d590}</UniqueIdentifier>
     </Filter>
+    <Filter Include="Header Files\common">
+      <UniqueIdentifier>{6c9ad2f2-bc8d-4e25-9c5c-c4440c60991c}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   <ItemGroup>
@@ -25,11 +28,17 @@
       <Filter>Source Files\common</Filter>
     </ClCompile>
+    <ClCompile Include="chat.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
-    <ClInclude Include="..\..\common\message.h">
-      <Filter>Source Files\common</Filter>
+    <ClInclude Include="chat.h">
+      <Filter>Header Files</Filter>
     </ClInclude>
     <ClInclude Include="..\..\common\compiler.h">
-      <Filter>Source Files\common</Filter>
+      <Filter>Header Files\common</Filter>
+    </ClInclude>
+    <ClInclude Include="..\..\common\message.h">
+      <Filter>Header Files\common</Filter>
     </ClInclude>
   </ItemGroup>
Index: client/Client/chat.cpp
===================================================================
--- client/Client/chat.cpp	(revision 6475138037f8825ef1e75833efa2789c0ebcabdd)
+++ client/Client/chat.cpp	(revision 6475138037f8825ef1e75833efa2789c0ebcabdd)
@@ -0,0 +1,61 @@
+#include "chat.h"
+
+chat::chat(void)
+{
+}
+
+chat::~chat(void)
+{
+}
+
+string chat::getInput()
+{
+   string temp = strEnteredInput;
+   strEnteredInput.clear();
+   return temp;
+}
+
+void chat::draw(ALLEGRO_FONT *font, ALLEGRO_COLOR color)
+{
+   for(int x=0; x<vctChat.size(); x++)
+      al_draw_text(font, color, 10, 10+x*15, ALLEGRO_ALIGN_LEFT, vctChat[x].c_str());
+
+   al_draw_text(font, color, 10, 460, ALLEGRO_ALIGN_LEFT, strPrompt.c_str());
+}
+
+void chat::addLine(string s)
+{
+   vctChat.push_back(s);
+}
+
+// returns true if the event was consumed, false if it should be passed on
+bool chat::processEvent(ALLEGRO_EVENT ev)
+{
+   ALLEGRO_KEYBOARD_STATE keys;
+   al_get_keyboard_state(&keys);
+
+   if (ev.type == ALLEGRO_EVENT_KEY_DOWN) {
+      char newChar = 0;
+
+      if (ALLEGRO_KEY_A <= ev.keyboard.keycode && ev.keyboard.keycode <= ALLEGRO_KEY_Z) {
+         newChar = 'a'+ev.keyboard.keycode-ALLEGRO_KEY_A;
+         if (al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, ALLEGRO_KEY_RSHIFT))
+            newChar -= 32;
+      }
+      if (ALLEGRO_KEY_0 <= ev.keyboard.keycode && ev.keyboard.keycode <= ALLEGRO_KEY_9)
+         newChar = '0'+ev.keyboard.keycode-ALLEGRO_KEY_0;
+
+      if (newChar != 0) {
+         strPrompt.append(1, newChar);
+         return true;
+      }
+
+      if (ev.keyboard.keycode == ALLEGRO_KEY_ENTER) {
+         strEnteredInput = strPrompt;
+         strPrompt.clear();
+         return true;
+      }
+   }
+   
+   return false;
+}
Index: client/Client/chat.h
===================================================================
--- client/Client/chat.h	(revision 6475138037f8825ef1e75833efa2789c0ebcabdd)
+++ client/Client/chat.h	(revision 6475138037f8825ef1e75833efa2789c0ebcabdd)
@@ -0,0 +1,28 @@
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include <allegro5/allegro.h>
+#include <allegro5/allegro_font.h>
+
+using namespace std;
+
+class chat
+{
+private:
+   vector<string> vctChat;
+   string strPrompt;
+   string strEnteredInput;
+public:
+   chat(void);
+   ~chat(void);
+
+   string getInput();
+
+   void draw(ALLEGRO_FONT *font, ALLEGRO_COLOR color);
+   void addLine(string s);
+
+   bool processEvent(ALLEGRO_EVENT ev);
+};
+
Index: client/Client/main.cpp
===================================================================
--- client/Client/main.cpp	(revision 9a3e6b166fac0f317e650d6c558d94c60ef9600e)
+++ client/Client/main.cpp	(revision 6475138037f8825ef1e75833efa2789c0ebcabdd)
@@ -26,6 +26,8 @@
 #include "../../common/message.h"
 
+#include "chat.h"
+
 #ifdef WINDOWS
-	#pragma comment(lib, "ws2_32.lib")
+   #pragma comment(lib, "ws2_32.lib")
 #endif
 
@@ -56,7 +58,5 @@
    bool doexit = false;
 
-   vector<string> vctChat;
-   string strPrompt;
-   string strEnteredInput;
+   chat chatConsole;
 
    if(!al_init()) {
@@ -161,5 +161,5 @@
       error("receiveMessage");
 	
-   vctChat.push_back(string(msgFrom.buffer));
+   chatConsole.addLine(msgFrom.buffer);
 
    al_start_timer(timer);
@@ -193,56 +193,42 @@
       }
       else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) {
-         switch(ev.keyboard.keycode) {
-            case ALLEGRO_KEY_UP:
-               key[KEY_UP] = true;
-               break;
- 
-            case ALLEGRO_KEY_DOWN:
-               key[KEY_DOWN] = true;
-               break;
- 
-            case ALLEGRO_KEY_LEFT: 
-               key[KEY_LEFT] = true;
-               break;
- 
-            case ALLEGRO_KEY_RIGHT:
-               key[KEY_RIGHT] = true;
-               break;
-
-			case ALLEGRO_KEY_ENTER:
-			   strEnteredInput = strPrompt;
-			   strPrompt.clear();
-
-			   if (strEnteredInput.compare("q") == 0) {
-			      doexit = true;
-		       }
-			   else
-			   {
-                  strcpy(msgTo.buffer, strEnteredInput.c_str());
-		          n=sendMessage(&msgTo, sock, &server);
-		          if (n < 0)
-			         error("sendMessage");
-
-		          n = receiveMessage(&msgFrom, sock, &from);
-		          if (n < 0)
-			         error("receiveMessage");
-
-		          vctChat.push_back(string(msgFrom.buffer));
-			   }
-
-			   break;
-         }
-
-		 if(ALLEGRO_KEY_A <= ev.keyboard.keycode && ev.keyboard.keycode <= ALLEGRO_KEY_Z)
-		 {
-            char newChar = 'a'+ev.keyboard.keycode-ALLEGRO_KEY_A;
-            strPrompt.append(1, newChar);
-		 }
-
-		 if(ALLEGRO_KEY_0 <= ev.keyboard.keycode && ev.keyboard.keycode <= ALLEGRO_KEY_9)
-		 {
-            char newChar = '0'+ev.keyboard.keycode-ALLEGRO_KEY_0;
-            strPrompt.append(1, newChar);
-		 }
+         bool eventConsumed = chatConsole.processEvent(ev);
+
+         if (eventConsumed) {
+            string input = chatConsole.getInput();
+            if (!input.empty()) {
+               cout << "input: " << input << endl;
+               strcpy(msgTo.buffer, input.c_str());
+               
+               n=sendMessage(&msgTo, sock, &server);
+               if (n < 0)
+                  error("sendMessage");
+
+               n = receiveMessage(&msgFrom, sock, &from);
+               if (n < 0)
+                  error("receiveMessage");
+
+               chatConsole.addLine(string(msgFrom.buffer));
+               cout << "Added new line" << endl;
+            }
+         }else {
+            switch(ev.keyboard.keycode) {
+               case ALLEGRO_KEY_UP:
+                  key[KEY_UP] = true;
+                  break;
+ 
+               case ALLEGRO_KEY_DOWN:
+                  key[KEY_DOWN] = true;
+                  break;
+ 
+               case ALLEGRO_KEY_LEFT: 
+                  key[KEY_LEFT] = true;
+                  break;
+ 
+               case ALLEGRO_KEY_RIGHT:
+                  key[KEY_RIGHT] = true;
+                  break;
+            }
+         }
       }
       else if(ev.type == ALLEGRO_EVENT_KEY_UP) {
@@ -277,9 +263,6 @@
          al_draw_bitmap(bouncer, bouncer_x, bouncer_y, 0);
 
-		 for(int x=0; x<vctChat.size(); x++)
-            al_draw_text(font, al_map_rgb(255,255,255), 10, 10+x*15, ALLEGRO_ALIGN_LEFT, vctChat[x].c_str());
-
-		 al_draw_text(font, al_map_rgb(255,255,255), 10, 460, ALLEGRO_ALIGN_LEFT, strPrompt.c_str());
-         
+         chatConsole.draw(font, al_map_rgb(255,255,255));
+
          al_flip_display();
       }
