eventData.inputCode = 0;
						eventData.inputValue = 0;
						eventData.isConnected = 1;
						eventData.controllerID = G_XBOX_CONTROLLER;
                        listenerMutex.lock();
						for (iter = listeners.begin(); iter!= listeners.end(); ++iter)
							iter->first->OnEvent(GControllerUUIID, CONTROLLERCONNECTED, &eventData, sizeof(GCONTROLLER_EVENT_DATA));
                        listenerMutex.unlock();
					}


					if (XControllerSlotIndices[i] >= 0 && controllerState.dwPacketNumber!= XControllerLastPacket[i]) // add checks for events
					{
						CopyControllerState(&controllers[XControllerSlotIndices[i]], &oldState);
						eventData.isConnected = 1;
						eventData.controllerIndex = XControllerSlotIndices[i];


						XControllerLastPacket[i] = controllerState.dwPacketNumber;

						// Buttons

						if (((controllerState.Gamepad.wButtons & XINPUT_GAMEPAD_A)!= 0? 1.0f : 0.0f)!= oldState.controllerInputs[G_SOUTH_BTN])
						{
							controllersMutex.lock();
							controllers[XControllerSlotIndices[i]].controllerInputs[G_SOUTH_BTN] = (controllerState.Gamepad.wButtons & XINPUT_GAMEPAD_A)!= 0? 1.0f : 0.0f;
							eventData.inputCode = G_SOUTH_BTN;
							eventData.inputValue = controllers[XControllerSlotIndices[i]].controllerInputs[G_SOUTH_BTN];
							controllersMutex.unlock();

                            listenerMutex.lock();
							for (iter = listeners.begin(); iter!= listeners.end(); ++iter)
								iter->first->OnEvent(GControllerUUIID, CONTROLLERBUTTONVALUECHANGED, &eventData, sizeof(GCONTROLLER_EVENT_DATA));
                            listenerMutex.unlock();
						}

						if (((controllerState.Gamepad.wButtons & XINPUT_GAMEPAD_B)!= 0? 1.0f : 0.0f)!= oldState.controllerInputs[G_EAST_BTN])
						{
							controllersMutex.lock();
							controllers[XControllerSlotIndices[i]].controllerInputs[G_EAST_BTN] = (controllerState.Gamepad.wButtons & XINPUT_GAMEPAD_B)!= 0? 1.0f : 0.0f;
							eventData.inputCode = G_EAST_BTN;
							eventData.inputValue = controllers[XControllerSlotIndices[i]].controllerInputs[G_EAST_BTN];
							controllersMutex.unlock();

                            listenerMutex.lock();
							for (iter = listeners.begin(); iter!= listeners.end(); ++iter)
								iter->first->OnEvent(GControllerUUIID, CONTROLLERBUTTONVALUECHANGED, &eventData, sizeof(GCONTROLLER_EVENT_DATA));
                            listenerMutex.unlock();
						}
						if (((controllerState.Gamepad.wButtons & XINPUT_GAMEPAD_Y)!= 0? 1.0f : 0.0f)!= oldState.controllerInputs[G_NORTH_BTN])
						{
							controllersMutex.lock();
							controllers[XControllerSlotIndices[i]].controllerInputs[G_NORTH_BTN] = (controllerState.Gamepad.wButtons & XINPUT_GAMEPAD_Y)!= 0? 1.0f : 0.0f;
							eventData.inputCode = G_NORTH_BTN;
							eventData.inputValue = controllers[XControllerSlotIndices[i]].controllerInputs[G_NORTH_BTN];
							controllersMutex.unlock();

                            listenerMutex.lock();
							for (iter = listeners.begin(); iter!= listeners.end(); ++iter)
								iter->first->OnEvent(GControllerUUIID, CONTROLLERBUTTONVALUECHANGED, &eventData, sizeof(GCONTROLLER_EVENT_DATA));
                            listenerMutex.unlock();
						}
						if (((controllerState.Gamepad.wButtons & XINPUT_GAMEPAD_X)!= 0? 1.0f : 0.0f)!= oldState.controllerInputs[G_WEST_BTN])
						{
							controllersMutex.lock();
							controllers[XControllerSlotIndices[i]].controllerInputs[G_WEST_BTN] = (controllerState.Gamepad.wButtons & XINPUT_GAMEPAD_X)!= 0? 1.0f : 0.0f;
							eventData.inputCode = G_WEST_BTN;
							eventData.inputValue = controllers[XControllerSlotIndices[i]].controllerInputs[G_WEST_BTN];
							controllersMutex.unlock();

                            listenerMutex.lock();
							for (iter = listeners.begin(); iter!= listeners.end(); ++iter)
								iter->first->OnEvent(GControllerUUIID, CONTROLLERBUTTONVALUECHANGED, &eventData, sizeof(GCONTROLLER_EVENT_DATA));
                            listenerMutex.unlock();
						}

						if (((controllerState.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER)!= 0? 1.0f : 0.0f)!= oldState.controllerInputs[G_LEFT_SHOULDER_BTN])
						{
							controllersMutex.lock();
							controllers[XControllerSlotIndices[i]].controllerInputs[G_LEFT_SHOULDER_BTN] = (controllerState.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER)!= 0? 1.0f : 0.0f;
							eventData.inputCode = G_LEFT_SHOULDER_BTN;
							eventData.inputValue = controllers[XControllerSlotIndices[i]].controllerInputs[G_LEFT_SHOULDER_BTN];
							controllersMutex.unlock();

                            listenerMutex.lock();
							for (iter = listeners.begin(); iter!= listeners.end(); ++iter)
								iter->first->OnEvent(GControllerUUIID, CONTROLLERBUTTONVALUECHANGED, &eventData, sizeof(GCONTROLLER_EVENT_DATA));
                            listenerMutex.unlock();
						}

						if (((controllerState.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER)!= 0? 1.0f : 0.0f)!= oldState.controllerInputs[G_RIGHT_SHOULDER_BTN])
						{
							controllersMutex.lock();
							controllers[XControllerSlotIndices[i]].controllerInputs[G_RIGHT_SHOULDER_BTN] = (controllerState.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER)!= 0? 1.0f : 0.0f;
							eventData.inputCode = G_RIGHT_SHOULDER_BTN;
							eventData.inputValue = controllers[XControllerSlotIndices[i]].controllerInputs[G_RIGHT_SHOULDER_BTN];
							controllersMutex.unlock();

                            listenerMutex.lock();
							for (iter = listeners.begin(); iter!= listeners.end(); ++iter)
								iter->first->OnEvent(GControllerUUIID, CONTROLLERBUTTONVALUECHANGED, &eventData, sizeof(GCONTROLLER_EVENT_DATA));
                            listenerMutex.unlock();
						}

						if (((controllerState.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT)!= 0? 1.0f : 0.0f)!= oldState.controllerInputs[G_DPAD_LEFT_BTN])
						{
							controllersMutex.lock();
							controllers[XControllerSlotIndices[i]].controllerInputs[G_DPAD_LEFT_BTN] = (controllerState.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT)!= 0? 1.0f : 0.0f;
							eventData.inputCode = G_DPAD_LEFT_BTN;
							eventData.inputValue = controllers[XControllerSlotIndices[i]].controllerInputs[G_DPAD_