문제

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?

도움이 되었습니까?

해결책

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; } });

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top