void ProcessKeyboard(CCWindow window) { // Read the current keyboard state KeyboardState currentKeyboardState = Keyboard.GetState(); var dispatcher = window.EventDispatcher; if (currentKeyboardState == priorKeyboardState || !dispatcher.IsEventListenersFor(CCEventListenerKeyboard.LISTENER_ID)) { priorKeyboardState = currentKeyboardState; return; } var keyboardEvent = new CCEventKeyboard(CCKeyboardEventType.KEYBOARD_PRESS); var keyboardState = new CCKeyboardState() { KeyboardState = currentKeyboardState }; keyboardEvent.KeyboardState = keyboardState; // Check for pressed/released keys. // Loop for each possible pressed key (those that are pressed this update) Keys[] keys = currentKeyboardState.GetPressedKeys(); for (int k = 0; k < keys.Length; k++) { // Was this key up during the last update? if (priorKeyboardState.IsKeyUp(keys[k])) { // Yes, so this key has been pressed //CCLog.Log("Pressed: " + keys[i].ToString()); keyboardEvent.Keys = (CCKeys)keys[k]; dispatcher.DispatchEvent(keyboardEvent); } } // Loop for each possible released key (those that were pressed last update) keys = priorKeyboardState.GetPressedKeys(); keyboardEvent.KeyboardEventType = CCKeyboardEventType.KEYBOARD_RELEASE; for (int k = 0; k < keys.Length; k++) { // Is this key now up? if (currentKeyboardState.IsKeyUp(keys[k])) { // Yes, so this key has been released //CCLog.Log("Released: " + keys[i].ToString()); keyboardEvent.Keys = (CCKeys)keys[k]; dispatcher.DispatchEvent(keyboardEvent); } } // Store the state for the next loop priorKeyboardState = currentKeyboardState; }