void (KeyEvent event) { if (event.isConsumed()) return; // already processed if (0 != event.getModifiers()) return; // modifier pressed if (KeyEvent.VK_ESCAPE != event.getKeyCode()) return; // not ESC boolean[] copied = new boolean[1]; PsiCopyPasteManager manager = getInstance(); if (manager.getElements(copied) == null) return; // no copied element if (copied[0]) return; // nothing is copied manager.clear(); event.consume(); }