/*
Copyright 2012 Opera Software ASA

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package com.opera.core.systems.internal.input;

import org.openqa.selenium.Keys;

/**
 * Represents a single key event.
 */
public class KeyEvent {

  private final Character character;
  private final Keys unicodeKey;

  public KeyEvent(char ch) {
    character = ch;
    unicodeKey = Keys.getKeyFromUnicode(character);
  }

  /**
   * Gets the event as its character representation.
   *
   * @return the character
   */
  public char getCharacter() {
    return character;
  }

  /**
   * Gets the event as its Unicode PUA key representation.
   *
   * @return the key
   */
  public Keys getKey() {
    return unicodeKey;
  }

  /**
   * Keys that are pressable but which doesn't yield any text are special, and a keyboard
   * implementation must likely treat them accordingly.
   *
   * @return true if event represents a "special", non-textual key; false otherwise
   */
  public boolean isSpecial() {
    return getKey() != null;
  }

  /**
   * Determines whether event is a modifier key.
   *
   * @return true if event is a modifier key, false otherwise
   */
  public boolean isModifier() {
    return KeyboardModifiers.isModifier(getKey());
  }

  /**
   * The Unicode PUA character for <code>NULL</code> signalises that all active modifier keys should
   * be released via a key up event.
   *
   * @return true if event is a modifier release, false otherwise
   */
  public boolean isModifierRelease() {
    return getKey() == Keys.NULL;
  }

  /**
   * The newline character, <code>\n</code>, must be handled as using the <kbd>Enter</kbd> key.
   *
   * @return true if event is a newline character, false otherwise
   */
  public boolean isNewLine() {
    return getCharacter() == '\n';
  }

}
@@ -829,16 +829,101 @@
 r = ch;%0A
+    // TODO(andreastt): Use Keys.getKeyFromUnicode(c) when Selenium 2.26 is released%0A
     unic
@@ -931,21 +931,16 @@
 deKey = 
-Keys.
 getKeyFr
@@ -2349,9 +2349,540 @@
 ';%0A  %7D%0A%0A
+  /**%0A   * Get the special key representation, %7B@link Keys%7D, of the supplied character if there is one. If%0A   * there is no special key tied to this character, null will be returned.%0A   *%0A   * @param key unicode character code%0A   * @return special key linked to the character code, or null if character is not a special key%0A   */%0A  private static Keys getKeyFromUnicode(char key) %7B%0A    for (Keys unicodeKey : Keys.values()) %7B%0A      if (unicodeKey.charAt(0) == key) %7B%0A        return unicodeKey;%0A      %7D%0A    %7D%0A%0A    return null;%0A  %7D%0A%0A
 %7D

Implement getKeyFromUnicode() locally for now