public static boolean dispatchKeyType(Event e, Handler<KeyEvent> handler) { final KeyEvent event = EventTranslator.toKeyEvent(e); if (e.getCharCode() == 0) return true; if (e.getCharCode() == '\n') return true; if (e.getCharCode() == '\r') return true; if (event.has(ModifierKey.META) || event.has(ModifierKey.ALT) || event.has(ModifierKey.CONTROL)) return true; handler.handle(event); return !event.isConsumed(); }
@Override public void onBrowserEvent(Event event) { if (cancelled) { return; } super.onBrowserEvent(event); assertEquals(KEY_CODE, event.getKeyCode()); // shouldn't throw: event.getCharCode(); }
private static KeyEvent toKeyEvent(Event e) { Key key = KeyCodeMapper.getKey(e.getKeyCode()); Set<ModifierKey> modifiers = new HashSet<>(); if (e.getCtrlKey()) { modifiers.add(ModifierKey.CONTROL); } if (e.getAltKey()) { modifiers.add(ModifierKey.ALT); } if (e.getShiftKey()) { modifiers.add(ModifierKey.SHIFT); } if (e.getMetaKey()) { modifiers.add(ModifierKey.META); } return new KeyEvent(key, (char) e.getCharCode(), modifiers); }