Question

I have a KeyEvent object and i only want to process it if the key is a visible one. With visible i mean like one of these characters abcdefghijklmnopqrstuvwxy1234567890^°!"§$%&/()=?`@+#*',.-;:_" I do not want to process SPACE, ESC, BACKSPACE, DEL...

What i'm calling right now is e.isActionKey() and if it is, i don't process it. But that includes only a few keys like PAGE_UP, PAGE_DOWN.

What is the best way to filter out all the keys that i don't want?

Was it helpful?

Solution

Well i basically already gave the answer :)

KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() { @Override public boolean dispatchKeyEvent(KeyEvent e) { String validString = "^°1!2\"§3$4%5&6/7{(8[)9]=0}?ß\\`´q@we€rtzuiopü*+~asdfghjklöä'#<>yxcvbnmµ;,:._-"; if (e.getID() == KeyEvent.KEY_TYPED && validString.indexOf(String.valueOf(e.getKeyChar()).toLowerCase()) != -1) { if (CardPanelView.this.cardLayout.getCurrentCard() == tabbedPane) { CardPanelView.this.controller.callSetSearchText(Character.toString(e.getKeyChar())); } } return false; } });

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top