public MapDef getDef(KeyPressedEvent e) {

        if (e.getID() == KeyPressedEvent.KEY_RELEASED) {
            MapDef def = (MapDef) keysCurrentlyDown.get(e
                    .getCharCode());
            registerKeyPressedEvent(e, def);
      //      if (e.getID() == KeyPressedEvent.KEY_RELEASED)
                //logger.debug("Released: " + e.getKeyCode()
           //             + " returned scancode: "
             //           + ((def != null) ? "" + def.getScancode() : "null"));
            return def;
        }

        updateCapsLock(e);

        Iterator i = keyMap.iterator();
        int smallestDist = -1;
        MapDef best = null;

        boolean noScanCode = !hasScancode((char)e.getCharCode());

        while (i.hasNext()) {
            MapDef current = (MapDef) i.next();
            boolean applies;

            if ((e.getID() == KeyPressedEvent.KEY_PRESSED)) {
                applies = current.appliesToPressed(e);
            } else if ((!lastEventMatched) && (e.getID() == KeyPressedEvent.KEY_PRESSED)) {
            	
                applies = current.appliesToTyped(e, capsLockDown, option);
            } else
                applies = false;

            if (applies) {
                int d = current.modifierDistance(e, capsLockDown);
                if ((smallestDist == -1) || (d < smallestDist)) {
                    smallestDist = d;
                    best = current;
                }
            }
        }

      /*  if (e.getID() == KeyPressedEvent.KEY_PRESSED)
            //logger.debug("Pressed: " + e.getKeyCode() + " returned scancode: "
                    + ((best != null) ? "" + best.getScancode() : "null"));
        if (e.getID() == KeyPressedEvent.KEY_TYPED)
            //logger.debug("Typed: " + e.getKeyChar() + " returned scancode: "
                    + ((best != null) ? "" + best.getScancode() : "null"));
*/
        registerKeyPressedEvent(e, best);

        return best;
    }